0
votes

If you DM the bot it will send a message and add some reactions, it then waits for the user to add reaction before doing something.

My problem is if the user DMs the bot again, it will send another message and if the user reacts to any of the bot messages, bot will do the things twice or more depending on how many messages you got from the bot.

Is there a way to make the bot to not send another message if there's a current message with reaction and wait for the user to react first before the bot can send another message with reaction again? Thanks.

async def on_message(self, message):
    if message.author.bot:
        return

    if isinstance(message.channel, discord.DMChannel):
        dm = await message.channel.send('test')
        await dm.add_reaction("1️⃣")
   
    def check(reaction, user):
        return user == message.author and str(reaction.emoji) in ["1️⃣"]

    while True:
        try:
            reaction, user = await self.client.wait_for("reaction_add", timeout=15, check=check)
            if str(reaction.emoji) == "1️⃣":
                # do something here
 
        except asyncio.TimeoutError:
            await dm.delete()
            break
3
what's the purpose of that while loop?Łukasz Kwieciński

3 Answers

0
votes

The syntax is wrong, and why did you add a while loop?

Here's the fixed code:

@commands.Cog.listener()
async def on_message(self, message):
    if message.author.bot:
        return

    if isinstance(message.channel, discord.DMChannel):
        # Sending the message and adding reactions
        msg = await message.channel.send('Test')
        await msg.add_reaction('1️⃣')

        check = lambda reaction, user: user == message.author and str(reaction) in your_list_of_reactions

        try:
            # Waiting for the reaction
            reaction, user = await self.client.wait_for('reaction_add', check=check, timeout=15.0)

            if str(reaction) == "1️⃣":
                # do something

        except asyncio.TimeoutError:
            await msg.delete()

    # Adding this so the rest commands will work
    await bot.process_commands(message)
    
0
votes

Fixed it by making a database for every message. Thanks for the people who tried to help!

0
votes

I may be a little late, but here is a solution that worked for me

In your "check" statement you should add this to it

and reaction.message == msg

So it will look something like this

def check(reaction, user):
    return user == message.author and str(reaction.emoji) in ["1️⃣"] and reaction.message == msg