mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[V3 Menu] Don't block on adding reactions (#1808)
* [V3 Menu] Don't block on adding reactions * Add a comment
This commit is contained in:
parent
b041d59fc7
commit
c149f00f82
@ -5,10 +5,14 @@ https://github.com/Lunar-Dust/Dusty-Cogs/blob/master/menu/menu.py
|
|||||||
Ported to Red V3 by Palm\_\_ (https://github.com/palmtree5)
|
Ported to Red V3 by Palm\_\_ (https://github.com/palmtree5)
|
||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import contextlib
|
||||||
|
from typing import Union, Iterable
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
from redbot.core import commands
|
from redbot.core import commands
|
||||||
|
|
||||||
|
_ReactableEmoji = Union[str, discord.Emoji]
|
||||||
|
|
||||||
|
|
||||||
async def menu(
|
async def menu(
|
||||||
ctx: commands.Context,
|
ctx: commands.Context,
|
||||||
@ -66,8 +70,8 @@ async def menu(
|
|||||||
message = await ctx.send(embed=current_page)
|
message = await ctx.send(embed=current_page)
|
||||||
else:
|
else:
|
||||||
message = await ctx.send(current_page)
|
message = await ctx.send(current_page)
|
||||||
for key in controls.keys():
|
# Don't wait for reactions to be added (GH-1797)
|
||||||
await message.add_reaction(key)
|
ctx.bot.loop.create_task(_add_menu_reactions(message, controls.keys()))
|
||||||
else:
|
else:
|
||||||
if isinstance(current_page, discord.Embed):
|
if isinstance(current_page, discord.Embed):
|
||||||
await message.edit(embed=current_page)
|
await message.edit(embed=current_page)
|
||||||
@ -148,4 +152,12 @@ async def close_menu(
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
async def _add_menu_reactions(message: discord.Message, emojis: Iterable[_ReactableEmoji]):
|
||||||
|
"""Add the reactions"""
|
||||||
|
# The task should exit silently if the message is deleted
|
||||||
|
with contextlib.suppress(discord.NotFound):
|
||||||
|
for emoji in emojis:
|
||||||
|
await message.add_reaction(emoji)
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_CONTROLS = {"⬅": prev_page, "❌": close_menu, "➡": next_page}
|
DEFAULT_CONTROLS = {"⬅": prev_page, "❌": close_menu, "➡": next_page}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user