Skip to main content
Context menu commands are application commands that appear when you right-click (or tap) on a user or message.

UserCommand

A class that implements the protocol for user context menu commands. These commands appear when right-clicking on a user.

Attributes

name
str
The name of the command.
callback
coroutine
The coroutine that is executed when the command is called. Must accept ctx and user parameters.
guild_ids
Optional[List[int]]
The ids of the guilds where this command will be registered.
nsfw
bool
Whether the command should be restricted to 18+ channels and users. Apps intending to be listed in the App Directory cannot have NSFW commands.
default_member_permissions
Permissions
The default permissions a member needs to be able to run the command.
cog
Optional[Cog]
The cog that this command belongs to. None if there isn’t one.
checks
List[Callable]
A list of predicates that verifies if the command could be executed with the given ApplicationContext as the sole parameter.
cooldown
Optional[Cooldown]
The cooldown applied when the command is invoked. None if the command doesn’t have a cooldown.
name_localizations
Dict[str, str]
The name localizations for this command. The values of this should be "locale": "name". See Discord’s locales documentation for valid locales.
integration_types
Set[IntegrationType]
The installation contexts where this command is available. Unapplicable for guild commands.
contexts
Set[InteractionContextType]
The interaction contexts where this command is available. Unapplicable for guild commands.

Methods

copy()

Creates a copy of this command. Returns: UserCommand - A new instance of this command.

MessageCommand

A class that implements the protocol for message context menu commands. These commands appear when right-clicking on a message.

Attributes

name
str
The name of the command.
callback
coroutine
The coroutine that is executed when the command is called. Must accept ctx and message parameters.
guild_ids
Optional[List[int]]
The ids of the guilds where this command will be registered.
nsfw
bool
Whether the command should be restricted to 18+ channels and users. Apps intending to be listed in the App Directory cannot have NSFW commands.
default_member_permissions
Permissions
The default permissions a member needs to be able to run the command.
cog
Optional[Cog]
The cog that this command belongs to. None if there isn’t one.
checks
List[Callable]
A list of predicates that verifies if the command could be executed with the given ApplicationContext as the sole parameter.
cooldown
Optional[Cooldown]
The cooldown applied when the command is invoked. None if the command doesn’t have a cooldown.
name_localizations
Dict[str, str]
The name localizations for this command. The values of this should be "locale": "name". See Discord’s locales documentation for valid locales.
integration_types
Set[IntegrationType]
The installation contexts where this command is available. Unapplicable for guild commands.
contexts
Set[InteractionContextType]
The interaction contexts where this command is available. Unapplicable for guild commands.

Methods

copy()

Creates a copy of this command. Returns: MessageCommand - A new instance of this command.

user_command()

Decorator for creating user context menu commands.
name
str
The name of the command. Defaults to the function name.
guild_ids
Optional[List[int]]
A list of guild IDs where this command will be registered. If not provided, the command is global.
default_member_permissions
Optional[Permissions]
The default permissions required to use this command.
nsfw
bool
default:"False"
Whether the command is age-restricted.
contexts
Optional[Set[InteractionContextType]]
The contexts where this command can be used.
integration_types
Optional[Set[IntegrationType]]
The installation types this command is available for.
Returns: Callable[..., UserCommand] - A decorator that converts the provided method into a UserCommand.

message_command()

Decorator for creating message context menu commands.
name
str
The name of the command. Defaults to the function name.
guild_ids
Optional[List[int]]
A list of guild IDs where this command will be registered. If not provided, the command is global.
default_member_permissions
Optional[Permissions]
The default permissions required to use this command.
nsfw
bool
default:"False"
Whether the command is age-restricted.
contexts
Optional[Set[InteractionContextType]]
The contexts where this command can be used.
integration_types
Optional[Set[IntegrationType]]
The installation types this command is available for.
Returns: Callable[..., MessageCommand] - A decorator that converts the provided method into a MessageCommand.

Examples

import discord

bot = discord.Bot()

@bot.user_command(name="User Info")
async def user_info(ctx: discord.ApplicationContext, user: discord.User):
    await ctx.respond(f"**User:** {user.name}\n**ID:** {user.id}\n**Created:** {user.created_at}")

bot.run("token")

Build docs developers (and LLMs) love