【问题标题】:Discord py bot not triggering and ignoring commandsDiscord py bot不会触发和忽略命令
【发布时间】:2021-09-20 12:52:59
【问题描述】:

我有这个机器人,每次有人使用on_message 事件发送消息时都会检查,并且由于某种原因,机器人的其他命令似乎被忽略了。 我在删除检查消息的功能后发现了这一点,并且命令运行良好。

这是on_message事件代码:

@client.event
async def on_message(message):
    text = message.content
    chann = message.channel.id
    yes1 = False
    yes = False
    for ide in ids:
        if message.author.id == ide:
            yes1 = True
    for strf in comms:
        if text.startswith(strf):
            yes = True
    if (yes == False) and (yes1 == False) and (chann == 822089739502616576) and (message.author.id != 769302967803183124):
        print(message.author.id)
        msg = await message.channel.send('lahne kel el commands ye bhim')
        await message.delete()
        await asyncio.sleep(2)
        print('deleting message')
        await msg.delete()
    if yes and (message.author.id != 769302967803183124) and (message.channel.id == 331562608467509249):
        print(message.author.id)
        msg = await message.channel.send('mech lahne tekteb el commands ye bhim')
        await message.delete()
        await asyncio.sleep(2)
        print('deletingmessage')
        await msg.delete()
    if yes1 and (chann == 331562608467509249) and (message.author.id != 769302967803183124):
        await message.delete()

我不知道问题出在哪里。

【问题讨论】:

    标签: discord discord.py bots


    【解决方案1】:

    您需要将await client.process_commands(message) 添加到 on_message 协程的末尾。

    作为docs 状态:

    默认情况下,这个协程在 on_message() 事件中被调用。如果你选择覆盖 on_message() 事件,那么你也应该调用这个协程。

    【讨论】:

    • 非常感谢。看来我没有很好地阅读文档哈哈。无论如何它工作了谢谢你救了我
    猜你喜欢
    • 2020-01-09
    • 2020-07-30
    • 2021-06-15
    • 2020-12-23
    • 2020-11-11
    • 1970-01-01
    • 2021-09-07
    • 2020-12-15
    • 2021-08-28
    相关资源
    最近更新 更多