我正在尝试创建一个事件,以便当有人发送消息时它会回复它

Im trying to make a event so that when someone makes a message it replys to it

到目前为止,就像我说的那样,我正在尝试制作一个机器人,这样当有人发出消息时,它会以 "Hello" 等进行响应,但是当我尝试这样做时,我发现该机器人会自行响应.

我的代码:

@bot.event
async def on_message(message):

您只需检查 message.author 是否是您的 bot

@bot.event
async def on_message(message):
    if message.author == bot.user: # check if the author of message is your bot
        return

    # rest of your code
    
    await bot.process_commands(message) # to correctly process commands 

您可能还想添加 await bot.process_commands(message) 以确保您的 commands will work if you decide to use them. Check this link to see why do you have to use it