在不和谐机器人中重复特定消息的功能

时间:2021-07-21 18:41:30

标签: python discord.py

所以,我正在为我的机器人编写一些新的代码,当有人说字母“h”时,机器人会在聊天中重复相同的字母。然而,机器人似乎是这样做的,但是这条消息说了 5 次,而且一遍又一遍地重复。

不仅如此,当有人说任何话时,机器人会说 h 5 次,一遍又一遍。

代码如下:

@client.event
    async def on_message(message):
    if message.content.find("h") != 1:
            await message.channel.send("h")

2 个答案:

答案 0 :(得分:1)

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Download</title> </head> <body> <a href="Sample.mp3" download="Song_name"><button>Click here </button></a> </body> </html> 将对包括机器人本身在内的每条消息做出反应。忽略机器人消息的最佳方法是这样的。

on_message

答案 1 :(得分:-2)

那是因为您要从 1 开始为邮件内容编制索引,而您应该从 0 开始:

if message.content.find("h") != 0:

顺便说一句,如果目的是忽略机器人消息,您可以明确地这样做:

if message.author != client.user:
    await message.channel.send("h")