【问题标题】:Discord.py on_message wont stop from sending the same messageDiscord.py on_message 不会停止发送相同的消息
【发布时间】:2021-08-11 14:08:13
【问题描述】:

我有一个不和谐的机器人,它应该在某些用户说出没有前缀的内容时发送消息。例如“测试”,当一个用户在频道中说“测试”时,机器人应该以“测试”响应,它的工作,但问题是,即使用户已经停止发送“测试”,机器人也不会停止发送“测试” ”。这是代码。

@client.event
async def on_message(message):
    if 'test' in message.content:
        await message.channel.send('testing')

【问题讨论】:

  • 对于未来,'test' 在 'testing' 内部,这会导致循环。

标签: python discord.py


【解决方案1】:

您的机器人正在查看自己的消息。

添加一个防范;如果消息的作者是 bot 用户本身,请不要对其进行操作。

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if 'test' in message.content:
        await message.channel.send('testing')

【讨论】:

    猜你喜欢
    • 2019-10-28
    • 2022-07-09
    • 2020-11-10
    • 2021-07-08
    • 1970-01-01
    • 2020-09-16
    • 2015-10-04
    • 2022-01-11
    • 2021-07-23
    相关资源
    最近更新 更多