S
S
Soneiko2021-04-07 21:52:42
Python
Soneiko, 2021-04-07 21:52:42

exceptions not working?

@pybot.command()
async def to(ctx, member: discord.Member):
    emojis = ['✅', '❌']
    load = discord.Embed(title='', description = f"")
    load.set_author(name= pybot.user.name, icon_url= pybot.user.avatar_url)
    load.set_footer(text= f"✅ - принять запрос, ❌ - отклонить запрос.")
    message = await ctx.send(embed = load)
    for emoji in emojis:
        await message.add_reaction(emoji)

    try:
        def check(reaction, user):
            if user.bot is False and user.id == member.id:
                return (user and str(reaction.emoji) == '✅') or (user and str(reaction.emoji) == '❌')
            elif user.bot is True:
                pass


        reaction, user = await pybot.wait_for('reaction_add', timeout= 1, check=check)
        await message.clear_reactions()
    except asyncio.TimeoutError:
        await message.edit("Время истекло") 
    else:
            if reaction.emoji == '✅':
                load = discord.Embed(title='', description = f"")
                load.set_author(name= pybot.user.name, icon_url= pybot.user.avatar_url)
                load.set_footer(text= f"")
                load.set_image(url = f"")
                await message.edit(embed = load)
            elif reaction.emoji == '❌':
                load = discord.Embed(title='', description = f"")
                load.set_author(name= pybot.user.name, icon_url= pybot.user.avatar_url)
                load.set_footer(text= f"")
                await message.edit(embed = load)
                pass
            else:
                pass

There is a piece of code. What is the problem, I set the wait time in wait_for, after which the TimeoutError error should be triggered
and this piece of code should be processed
except asyncio.TimeoutError:
        await message.edit("Время истекло")

but for some reason it does not catch it
606dff39deccc620649177.png
in the line
reaction, user = await pybot.wait_for('reaction_add', timeout= 1, check=check)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-04-07
@SoreMix

Isn't this a default exception?
except TimeoutError:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question