discord.py bot 正在发送垃圾邮件,在 on_message 事件中

时间:2021-04-29 18:08:30

标签: discord discord.py

discord.py 存在问题。

@client.event
async def on_message(message):
    if message.author != message.author:
        return
    else:
        if message == "Buck" or "buck":
           await message.channel.send("Yes, he's the Chairman of Dallas!")

它基本上无限重复“是的,他是达拉斯的主席”,这可能会使我因滥用 API 而被禁止,并可能使我未能通过委员会。

2 个答案:

答案 0 :(得分:5)

这样的表达:

if x == "foo" or "bar" or "baz":

Python 是这样解释的:

if (x == "foo") or ("bar") or ("baz"):

如果第一个表达式 (x == "foo") 不为真,则第二个 ("bar") 为真,所以这个复合条件总是通过。

试试这个:

if x == "foo" or x == "bar" or x == "baz":

或者,甚至更好:

if x in ("foo", "bar", "baz"):

此外,您正在比较整个 discord.Message 实例,而不仅仅是内容。

修复您的代码:

if message.content in ("Buck", "buck"):

答案 1 :(得分:0)

这应该有效:

@client.event async def on_message(message): if message.author == bot.user: return if message.content.lower() == "buck": await message.channel.send("Yes, he's the Chairman of Dallas!")

bot 此处指的是您的 discord.Bot 实例。