How do i check the reaction content in discord.py?

Viewed 1948

I am creating a ticket system. And i want a confirmation with the /close command. But how do i do that? I tried it wit an if statement but it didnt work. This is what i have:

@bot.command(name='Close', aliases=['close'])
async def close(ctx):
    if ctx.message.channel.name.startswith('ticket'):
        msg = 'The ticket is closed. If you aren\'t done yet react to this message with , if you are react with ️'
        embed = discord.Embed(title='Closed ticket', description=msg)
        message = await ctx.send(content=None, embed=embed)
        await message.add_reaction('')
        await message.add_reaction('️')
        await ctx.message.channel.set_permissions(ctx.author, send_messages=False)
        reaction = await bot.wait_for('reaction')
        if reaction.content == '️':
            countdown = await ctx.send('**Ticket will be closed in 10 seconds**')
            await asyncio.sleep(1)
            await countdown.edit(content='**Ticket will be closed in 9 seconds**')
            await asyncio.sleep(1)
            await countdown.edit(content='**Ticket will be closed in 8 seconds**')
            await asyncio.sleep(1)
            await countdown.edit(content='**Ticket will be closed in 7 seconds**')
            await asyncio.sleep(1)
            await countdown.edit(content='**Ticket will be closed in 6 seconds**')
            await asyncio.sleep(1)
            await countdown.edit(content='**Ticket will be closed in 5 seconds**')
            await asyncio.sleep(1)
            await countdown.edit(content='**Ticket will be closed in 4 seconds**')
            await asyncio.sleep(1)
            await countdown.edit(content='**Ticket will be closed in 3 seconds**')
            await asyncio.sleep(1)
            await countdown.edit(content='**Ticket will be closed in 2 seconds**')
            await asyncio.sleep(1)
            await countdown.edit(content='**Ticket will be closed in 1 second**')
            await asyncio.sleep(1)
            await ctx.message.channel.delete()
        if reaction.content == '':
            await ctx.send('**Ticket reopened**')
            await ctx.message.channel.set_permissions(ctx.autor, send_messages=True)
    else:
        await ctx.send('This isnt a ticket')

And i didn't even get any errors?

1 Answers

When waiting for a reaction to be added, you should use "reaction_add" instead of just "reaction":

@bot.command(...)
async def close(ctx):
    # Code

    # A check is usually encouraged when in a public channel,
    # but for a private channel with just one or two members, it should be fine
    reaction, user = await bot.wait_for("reaction_add")
    # Do some stuff

Two values are actually being returned from this wait_for, as seen in the documentation's example - reaction, and user.

Additionally, the discord.Reaction object has no content attribute.
You'll actually be looking for str(reaction) instead:

enter image description here


References:

Related