@@ -240,7 +240,10 @@ class Menu(metaclass=_MenuMeta):
240240 Whether to verify embed permissions as well.
241241 ctx: Optional[:class:`commands.Context`]
242242 The context that started this pagination session or ``None`` if it hasn't
243- been started yet.
243+ been started yet or :class:`nextcord.Interaction` is used instead.
244+ interaction: Optional[:class:`nextcord.Interaction`]
245+ The interaction that started this pagination session or ``None`` if it hasn't
246+ been started yet or :class:`commands.Context` is used instead.
244247 bot: Optional[:class:`commands.Bot`]
245248 The bot that is running this pagination session or ``None`` if it hasn't
246249 been started yet.
@@ -249,6 +252,9 @@ class Menu(metaclass=_MenuMeta):
249252 message of :meth:`send_initial_message`. You can set it in order to avoid
250253 calling :meth:`send_initial_message`\, if for example you have a pre-existing
251254 message you want to attach a menu to.
255+ ephemeral: :class:`bool`
256+ Whether to make the response ephemeral when using an interaction response.
257+ Note: Ephemeral messages do not support reactions.
252258 """
253259
254260 def __init__ (
@@ -270,6 +276,8 @@ def __init__(
270276 self ._running = True
271277 self .message = message
272278 self .ctx = None
279+ self .interaction = None
280+ self .ephemeral = False
273281 self .bot = None
274282 self ._author_id = None
275283 self ._buttons = self .__class__ .get_buttons ()
@@ -602,32 +610,47 @@ async def on_menu_button_error(self, exc: Exception):
602610
603611 async def start (
604612 self ,
605- ctx : commands .Context ,
613+ ctx : Optional [commands .Context ] = None ,
614+ interaction : Optional [nextcord .Interaction ] = None ,
606615 * ,
607616 channel : Optional [nextcord .abc .Messageable ] = None ,
608- wait : bool = False
617+ wait : bool = False ,
618+ ephemeral : bool = False ,
609619 ):
610620 """|coro|
611621
612622 Starts the interactive menu session.
613623
624+ To start a menu session, you must provide either a
625+ :class:`Context <nextcord.ext.commands.Context>` or an :class:`Interaction <nextcord.Interaction>` object.
626+
614627 Parameters
615628 -----------
616- ctx: :class:`Context`
629+ ctx: :class:`Context <nextcord.ext.commands.Context> `
617630 The invocation context to use.
631+ interaction: :class:`nextcord.Interaction`
632+ The interaction context to use for slash and
633+ component responses.
618634 channel: :class:`nextcord.abc.Messageable`
619635 The messageable to send the message to. If not given
620- then it defaults to the channel in the context.
636+ then it defaults to the channel in the context
637+ or interaction.
621638 wait: :class:`bool`
622639 Whether to wait until the menu is completed before
623640 returning back to the caller.
641+ ephemeral: :class:`bool`
642+ Whether to make the response ephemeral when using an
643+ interaction response. Note: ephemeral messages do not
644+ support reactions.
624645
625646 Raises
626647 -------
627648 MenuError
628649 An error happened when verifying permissions.
629650 nextcord.HTTPException
630651 Adding a reaction failed.
652+ ValueError
653+ No context or interaction was given or both were given.
631654 """
632655
633656 # Clear the reaction buttons cache and re-compute if possible.
@@ -636,11 +659,24 @@ async def start(
636659 except AttributeError :
637660 pass
638661
639- self .bot = bot = ctx .bot
662+ # ensure only one of ctx and interaction is set
663+ if ctx is None and interaction is None :
664+ raise ValueError ("ctx or interaction must be set." )
665+ if ctx is not None and interaction is not None :
666+ raise ValueError ("ctx and interaction cannot both be set." )
667+
640668 self .ctx = ctx
641- self ._author_id = ctx .author .id
642- channel = channel or ctx .channel
643- me = channel .guild .me if hasattr (channel , "guild" ) else ctx .bot .user
669+ self .interaction = interaction
670+ self .ephemeral = ephemeral
671+ if ctx is not None :
672+ self .bot = ctx .bot
673+ self ._author_id = ctx .author .id
674+ channel = channel or ctx .channel
675+ else :
676+ self .bot = getattr (interaction , "client" , interaction ._state ._get_client ())
677+ self ._author_id = interaction .user .id
678+ channel = channel or interaction .channel
679+ me = channel .guild .me if hasattr (channel , "guild" ) else self .bot .user
644680 permissions = channel .permissions_for (me )
645681 self .__me = nextcord .Object (id = me .id )
646682 self ._verify_permissions (ctx , channel , permissions )
@@ -656,13 +692,13 @@ async def start(
656692 self .__tasks .clear ()
657693
658694 self ._running = True
659- self .__tasks .append (bot .loop .create_task (self ._internal_loop ()))
695+ self .__tasks .append (self . bot .loop .create_task (self ._internal_loop ()))
660696
661697 async def add_reactions_task ():
662698 for emoji in self .buttons :
663699 await msg .add_reaction (emoji )
664700
665- self .__tasks .append (bot .loop .create_task (add_reactions_task ()))
701+ self .__tasks .append (self . bot .loop .create_task (add_reactions_task ()))
666702
667703 if wait :
668704 await self ._event .wait ()
0 commit comments