RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-569983

Kavermoki's questions

Martin Hope
Kavermoki
Asked: 2024-05-21 19:07:13 +0000 UTC

如何在函数中调用随机函数?

  • 5

我想随机打印函数的内容我收到消息:

<coroutine object process_start_command.<locals>.x at 0x0000024E0D550240>

程序:

import random
import randomfun

@dp.message_handler(commands=['start'])
async def process_start_command(message: types.Message):
    async def x():
        if True:
            f = [randomfun.ran_fun1, randomfun.ran_fun2]
            rand_x = random.choice(f)
            rand_x()
    await message.answer(f"{x}")

随机有趣文件:

from aiogram import types

async def ran_fun1(message: types.Message):
    await message.answer(text='Это рандомное сообщение 1')

async def ran_fun2(message: types.Message):
    await message.answer(text='Это рандомное сообщение 2')

我真的很困惑,我显然在喊出一些错误的东西。

python
  • 1 个回答
  • 81 Views
Martin Hope
Kavermoki
Asked: 2024-05-20 15:36:47 +0000 UTC

aiogram 中的错误 - TypeError: Message.answer() 缺少 1 个必需的位置参数:“self”。?

  • 5

开始研究任务调度器:

    from aiogram import Bot, types
    from aiogram.dispatcher import Dispatcher
    from aiogram.utils import executor
    from config import TOKEN
    from aiogram.contrib.fsm_storage.memory import MemoryStorage
    import logging
    from apscheduler.schedulers.asyncio import AsyncIOScheduler
    from datetime import datetime, timedelta
    
    logging.basicConfig(level=logging.INFO)
    bot = Bot(token=TOKEN)
    storage = MemoryStorage()
    dp = Dispatcher(bot = bot, storage=storage)
    
    
    async def send_message_time(message: types.Message):
        await message.answer(text='Это сообщение отправляется через несколько секунд после запуска бота')
    
    
    @dp.message_handler(commands=['start'])
    async def process_start_command(message: types.Message):
        schedule = AsyncIOScheduler(timezone="Europe/Moscow")
        schedule.add_job(send_message_time, trigger='date', run_date=datetime.now() + timedelta(seconds=5), kwargs={'message': types.Message})
        schedule.start()
        await message.answer("Здрасьте!")
    
    if __name__ == '__main__':
        logging.info("Starting bot...")
        executor.start_polling(dp)

我正在尝试实现一个在机器人启动“/start”时启动的任务,但出现错误:

    TypeError: Message.answer() missing 1 required positional argument: 'self'

那些。他要求添加一些必需的参数到Message.answer? 之前他说要添加一个参数text,虽然我不确定这是否有必要,但我在其他脚本中没有使用它,我添加了一个参数text,现在他要求另一个参数......我在网上搜索了所有我发现这是为了增加SELF争论......但这没有帮助。

完整回溯:

    Traceback (most recent call last):   File "C:\Program Files\Python311\Lib\site-packages\apscheduler\executors\base_py3.py", line 30, in run_coroutine_job
        retval = await job.func(*job.args, **job.kwargs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "C:\Users\*******\Desktop\*******************\********************\*****************\******************\************\tgbot3\bot.py", line 17, in send_message_time
        await message.answer(text='Это сообщение отправляется через несколько секунд после запуска бота')
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: Message.answer() missing 1 required positional argument: 'self'
python
  • 1 个回答
  • 26 Views
Martin Hope
Kavermoki
Asked: 2023-10-20 13:43:18 +0000 UTC

如果动态 HTML <li> 元素都相同,如何解析它们?

  • 5
dp.message_handler(text='Столовая')
async def help(message: types.Message, state: FSMContext):
    url = 'https://foodmonitoring.ru/13188/food'
    headers = {'Accept': '*/*',
                   'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36'}
    reg = requests.get(url, headers=headers).text
    soup = BeautifulSoup(reg, 'lxml')
    block = soup.find('div', class_="col-12 col-md align-self-center")
    stolovaya = block.find_all(itemprop="menuListItemLink")
    for item in stolovaya:
        item_text = item.text
        item_href = "https://foodmonitoring.ru" + item.get("href")
        print(f"{item_text}: {item_href}")

大家好。目前,它解析块 (div) 中的整个 xlsx 列表。该块有 html 元素“li”,其中包含我需要的链接,如何才能使其仅解析顶部的第三个“li”元素?请帮帮我..

例子

python
  • 1 个回答
  • 37 Views
Martin Hope
Kavermoki
Asked: 2023-10-17 15:19:12 +0000 UTC

有限状态机。过滤器必须是可调用和/或可等待的!

  • 5

我用的是 FSM,aiogram 2*。我收到以下错误: TypeError:过滤器必须可调用和/或可等待!

一切似乎都是按照FSM的指示进行的。我知道这是一个类型错误。但也许在版本 2 aiogram 中写法有所不同?我在文档中找不到它。先感谢您!

class UserStates(StatesGroup):
    find_group = State()

@dp.message_handler(text=['Найти группу'])
async def func(message: types.Message, state: FSMContext):
    keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
    await message.answer("Введите номер группы", reply_markup=keyboard)
    state.set_state(UserStates.find_group)

@dp.message_handler(UserStates.find_group)
async def func(message: types.Message, state: FSMContext):
    if(message.text == '7'):
        await bot.send_message(message.chat.id, "Вы ввели номер группы 7")
    elif(message.text == '6'):
        await bot.send_message(message.chat.id, "Вы ввели номер группы 6")
    else:
        await bot.send_message(message.chat.id, "Такой группы не существует")
    state.clear()

错误:

C:\Users\******\AppData\Local\Programs\Python\Python39\python.exe C:\Users\******\Desktop\pythonProjectuchenik\pythonProjectuchenik\main.py 
Traceback (most recent call last):
  File "C:\Users\******\Desktop\pythonProjectuchenik\pythonProjectuchenik\main.py", line 25, in <module>
    async def func(message: types.Message, state: FSMContext):
  File "C:\Users\******\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 560, in decorator
    self.register_message_handler(callback, *custom_filters,
  File "C:\Users\******\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 486, in register_message_handler
    self.message_handlers.register(self._wrap_async_task(callback, run_task), filters_set)
  File "C:\Users\******\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\handler.py", line 62, in register
    filters = get_filters_spec(self.dispatcher, filters)
  File "C:\Users\******\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\filters\filters.py", line 48, in get_filters_spec
    data.append(get_filter_spec(dispatcher, i))
  File "C:\Users\******\AppData\Local\Programs\Python\Python39\lib\site-packages\aiogram\dispatcher\filters\filters.py", line 28, in get_filter_spec
    raise TypeError('Filter must be callable and/or awaitable!')
TypeError: Filter must be callable and/or awaitable!

Process finished with exit code 1
aiogram-2.x
  • 1 个回答
  • 44 Views
Martin Hope
Kavermoki
Asked: 2023-10-16 21:29:28 +0000 UTC

为什么消息检查不起作用?蟒蛇 aiogram

  • 5
@dp.message_handler(text=['Найти группу'])
async def func(message: types.Message):
    await message.answer("Введите номер группы")
    if(message.text == '7'):
        await bot.send_message(message.chat.id, "Вы ввели номер группы 7")
python
  • 2 个回答
  • 35 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5