mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 11:48:55 -05:00
Allow menu() to listen to both adding and removing reactions (#4517)
This commit is contained in:
parent
a9dc93cf81
commit
34b912bc7c
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user