Search code examples
pythondiscorddiscord.pybots

Discord.py Repeat replies


My discord bot is repeating the on_message reply while they're trying to answer the next prompt.

How do I make each prompt its own separate thing and not get repeated replies? I tried looking it up but I don't know how to word my issues, I tried making more awaits but that does not really stop the fact that the on_message keeps happening each message.

https://i.sstatic.net/VxqKA.png

Here is the code :

async def on_message(message):
    if message.author.bot:
        return
    await message.reply("Are you reporting a bug or exploit? State 'bug' or 'exploit'")
    if message.content == 'bug':
        await message.reply("Use the following format:\nUsername:\nBug Report Explanation:\nProof:\nSend streamable files (mp4, Gyazo)")`

Solution

  • You are sending "Are you reporting a bug or exploit? State 'bug' or 'exploit'" as a reply to all the messages if they're sent by Discord users, as if message.author.bot: return is the only check performed before replying. You need to use if-elif-elses to make the bot reply accordingly.

    Here is one way you could do this (using ifs):

    async def on_message(message):
        if message.author.bot:
            return
        
        if message.content != "bug":
            await message.reply("Are you reporting a bug or exploit? State 'bug' or 'exploit'")
            
        if message.content == 'bug':
            await message.reply("Use the following format:\nUsername:\nBug Report Explanation:\nProof:\nSend streamable files (mp4, Gyazo)")
    

    I've wrapped the reply that gets repeated in an if that checks and sends it only if the message's content is not "bug". You can change the if in the if message.content == 'bug': to elif (equal to else if), as both are the same in this case.

    I suggest you learn the basics of Python before using a library like discord.py.