机器人在说某件事时会回复某个用户,但其余的代码不起作用

2024-09-27 17:52:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我的discord bot在我的朋友写了一条包含“squippy”这个词的discord消息时会回复我的朋友,并给出一个特定的响应,而其他没有用户ID的人会得到不同的响应(我很难解释,下面是代码):

代码示例:
example of code

而且效果很好,我想做什么就做什么!唯一的问题是,在我编写了这段代码之后,我的其他命令都不起作用。我删除了代码,它们工作得很好。我想弄清楚问题出在哪里,真是疯了。我将举两个例子,说明什么代码最主要是好的,嗯,在问题代码(?)

代码示例:
example of code 代码示例:
example of code


Tags: 代码用户命令id消息示例bot朋友
1条回答
网友
1楼 · 发布于 2024-09-27 17:52:02

以便在使用on_消息的第一个实例后,其他命令能够工作。您需要在on_消息函数的末尾添加await client.process_commands(message)。我假设您链接的所有命令都在on_message函数中

@client.event
async def on_message(message):
    
    if "squippy" in message.content:
        if message.author.id == USER ID:
            await message.channel.send("Nya Nya I'm your cat boy squip")

        else:
            await message.channel.send("I'm not *your* catboy pet")
    
    if "quantum toaster" in message.content:
        await message.channel.send("Let's get this bread")
    
    if any(word in msg for word in bad_words_2):
        await message.channel.send("Stop")
    

    await client.process_commands(message) # This line would be needed

相关问题 更多 >

    热门问题