【问题标题】:Discord bot deleting wrong messages?Discord bot 删除错误消息?
【发布时间】:2021-01-28 05:42:30
【问题描述】:

我有以下代码段:

if message.author.name == "Rythm" or "Groovy":
        print("Deleting a message because it is from Rythm or Groovy")
        print(message.author.name)
        await message.delete()

我想过滤掉来自其他 2 个机器人的无意义的机器人消息。

但是,这会导致机器人删除服务器上的每个用户消息。

Deleting a message because it is from Rythm or Groovy
StinkyDinky

用户“StinkyDinky”的消息被删除了。

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    因为你做了if message.author.name == "Rythm" or "Groovy"。这并不意味着消息作者是 Rythm 还是 Groovy,这意味着消息作者是 Rythm 还是 Groovy 存在。我知道这不是一个好的解释。但我想你会明白的。如果你这样做:

    if message.author.name == "Rythm" or message.author.name == "Great":
    

    您的问题将得到解决,如果您有任何不明白的地方,请发表评论。

    【讨论】:

      【解决方案2】:

      你的 if 语句总是计算为真。

      试试

      if message.author.name in ( "Rythm", "Groovy") :
      

      【讨论】:

        猜你喜欢
        • 2020-12-03
        • 2017-10-25
        • 2020-08-25
        • 2018-07-24
        • 1970-01-01
        • 2021-10-18
        • 1970-01-01
        • 2021-06-17
        • 2020-10-01
        相关资源
        最近更新 更多