Allow menu() to listen to both adding and removing reactions (#4517)

This commit is contained in:
Draper 2021-06-23 19:48:06 +01:00 committed by GitHub
parent a9dc93cf81
commit 34b912bc7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,11 +88,20 @@ async def menu(
return
try:
react, user = await ctx.bot.wait_for(
"reaction_add",
check=ReactionPredicate.with_emojis(tuple(controls.keys()), message, ctx.author),
timeout=timeout,
predicates = ReactionPredicate.with_emojis(tuple(controls.keys()), message, ctx.author)
tasks = [
asyncio.ensure_future(ctx.bot.wait_for("reaction_add", check=predicates)),
asyncio.ensure_future(ctx.bot.wait_for("reaction_remove", check=predicates)),
]
done, pending = await asyncio.wait(
tasks, timeout=timeout, return_when=asyncio.FIRST_COMPLETED
)
for task in pending:
task.cancel()
if len(done) == 0:
raise asyncio.TimeoutError()
react, user = done.pop().result()
except asyncio.TimeoutError:
if not ctx.me:
return
@ -126,10 +135,6 @@ async def next_page(
timeout: float,
emoji: str,
):
perms = message.channel.permissions_for(ctx.me)
if perms.manage_messages: # Can manage messages, so remove react
with contextlib.suppress(discord.NotFound):
await message.remove_reaction(emoji, ctx.author)
if page == len(pages) - 1:
page = 0 # Loop around to the first item
else:
@ -146,10 +151,6 @@ async def prev_page(
timeout: float,
emoji: str,
):
perms = message.channel.permissions_for(ctx.me)
if perms.manage_messages: # Can manage messages, so remove react
with contextlib.suppress(discord.NotFound):
await message.remove_reaction(emoji, ctx.author)
if page == 0:
page = len(pages) - 1 # Loop around to the last item
else: