1
votes

I am trying to make a confirmation poll on my code so that my bot will not clear messages without confirming that I want to do so.

I'm trying to do that with a reaction poll, where when I enter the command, it will send a message along with the tick and cross reactions. If I react with a tick emoji (<:nonatick:803586318369292289>), it will proceed to purge messages, while if I react with a cross emoji (<:RedTick:801684348502933525>), it will send another message and do nothing else.

I have gotten the part where it sends Are you sure you want to delete 1 messages? along with the bot's reactions. However, it does not respond further if I react to either of the emojis.

@client.command(pass_context=True)
@commands.has_permissions(manage_messages=True)
async def clear(ctx, number):
    number = int(number)
    moreoma = ctx.author.id
    message = await ctx.send("Are you sure you want to delete " + str(number) + " messages?")
# Adds reaction to above message
    for emoji in ('<:nonatick:803586318369292289>', '<:RedTick:801684348502933525>'):
        await message.add_reaction(emoji)

    def check(reaction, user):
        return user.id == moreoma and str(reaction.emoji) in ['<:nonatick:803586318369292289>',
                                                              '<:RedTick:801684348502933525>']

    reaction, user = await client.wait_for('reaction_add', timeout=5, check=check)
    if reaction.emoji == '<:nonatick:803586318369292289>':
        await ctx.channel.purge(limit=number + 2, check=lambda msg: not msg.pinned)
    elif reaction.emoji == '<:RedTick:801684348502933525>':
        await ctx.send("aight looks like we are not clearing messages as of now. ")

Intents are enabled in my code:

intents = discord.Intents(messages=True, guilds=True)
intents.reactions = True
intents.members = True

This is what happens when I use the command. This

Is it a problem with how it checks whether I have reacted?

Thanks for any help in advance!

1

1 Answers

0
votes

you can do this using try/except

@client.command(pass_context=True)
@commands.has_permissions(manage_messages=True)
async def clear(ctx, number):
    number = int(number)
    moreoma = ctx.author.id
    message = await ctx.send("Are you sure you want to delete " + str(number) + " messages?")

    emojis = ['<:nonatick:803586318369292289>', '<:RedTick:801684348502933525>']

    # Adds reaction to above message
    for emoji in (emojis):
        await message.add_reaction(emoji)

    def check(reaction, user):
        reacted = reaction.emoji
        return user.id == moreoma and str(reaction.emoji) in emojis

    try:
        reaction, user = await client.wait_for('reaction_add', timeout=10, check=check)
    except asyncio.TimeoutError:
        await ctx.send("timeout")
    else:
        if str(reacted) == '<:nonatick:803586318369292289>':
            await ctx.channel.purge(limit=number + 2, check=lambda msg: not msg.pinned)
        elif reaction.emoji == '<:RedTick:801684348502933525>':
            await ctx.send("aight looks like we are not clearing messages as of now. ")