Application Commands

Command Permission Decorators

@discord.commands.default_permissions(**perms)[ソース]

A decorator that limits the usage of an application command to members with certain permissions.

The permissions passed in must be exactly like the properties shown under discord.Permissions.

注釈

These permissions can be updated by server administrators per-guild. As such, these are only "defaults", as the name suggests. If you want to make sure that a user always has the specified permissions regardless, you should use an internal check such as has_permissions().

パラメータ:

**perms (bool) -- An argument list of permissions to check for.

戻り値の型:

Callable

サンプル

from discord import default_permissions

@bot.slash_command()
@default_permissions(manage_messages=True)
async def test(ctx):
    await ctx.respond('You can manage messages.')
@discord.commands.guild_only[ソース]

A decorator that limits the usage of an application command to guild contexts. The command won't be able to be used in private message channels.

戻り値の型:

Callable

サンプル

from discord import guild_only

@bot.slash_command()
@guild_only()
async def test(ctx):
    await ctx.respond("You're in a guild.")
@discord.commands.is_nsfw[ソース]

A decorator that limits the usage of an application command to 18+ channels and users. In guilds, the command will only be able to be used in channels marked as NSFW. In DMs, users must have opted into age-restricted commands via privacy settings.

Note that apps intending to be listed in the App Directory cannot have NSFW commands.

戻り値の型:

Callable

サンプル

from discord import is_nsfw

@bot.slash_command()
@is_nsfw()
async def test(ctx):
    await ctx.respond("This command is age restricted.")

Commands

Shortcut Decorators

@discord.commands.application_command(*, cls=<class 'discord.commands.core.SlashCommand'>, checks=..., cog=..., contexts=..., cooldown=..., default_member_permissions=..., description=..., description_localizations=..., guild_ids=..., guild_only=..., integration_types=..., name=..., name_localizations=..., nsfw=..., options=..., parent=..., **kwargs)[ソース]

A decorator that transforms a function into an ApplicationCommand. More specifically, usually one of SlashCommand, UserCommand, or MessageCommand. The exact class depends on the cls parameter. By default, the description attribute is received automatically from the docstring of the function and is cleaned up with the use of inspect.cleandoc. If the docstring is bytes, then it is decoded into str using utf-8 encoding. The name attribute also defaults to the function name unchanged.

Added in version 2.0.

パラメータ:
戻り値:

A decorator that converts the provided method into an ApplicationCommand, or subclass of it.

戻り値の型:

Callable[..., TypeVar(C, bound= MessageCommand | SlashCommand | UserCommand)]

例外:

TypeError -- If the function is not a coroutine or is already a command.

@discord.commands.command(**kwargs)[ソース]

An alias for application_command().

注釈

This decorator is overridden by ext.commands.command().

Added in version 2.0.

戻り値:

A decorator that converts the provided method into an ApplicationCommand.

戻り値の型:

Callable[..., ApplicationCommand]

@discord.commands.slash_command(*, checks=..., cog=..., contexts=..., cooldown=..., default_member_permissions=..., description=..., description_localizations=..., guild_ids=..., guild_only=..., integration_types=..., name=..., name_localizations=..., nsfw=..., options=..., parent=..., **kwargs)[ソース]

Decorator for slash commands that invokes application_command().

Added in version 2.0.

戻り値:

A decorator that converts the provided method into a SlashCommand.

戻り値の型:

Callable[..., SlashCommand]

パラメータ:
@discord.commands.user_command(*, checks=..., cog=..., contexts=..., cooldown=..., default_member_permissions=..., guild_ids=..., guild_only=..., integration_types=..., name=..., name_localizations=..., nsfw=..., **kwargs)[ソース]

Decorator for user commands that invokes application_command().

Added in version 2.0.

戻り値:

A decorator that converts the provided method into a UserCommand.

戻り値の型:

Callable[..., UserCommand]

パラメータ:
@discord.commands.message_command(*, checks=..., cog=..., contexts=..., cooldown=..., default_member_permissions=..., guild_ids=..., guild_only=..., integration_types=..., name=..., name_localizations=..., nsfw=..., **kwargs)[ソース]

Decorator for message commands that invokes application_command().

Added in version 2.0.

戻り値:

A decorator that converts the provided method into a MessageCommand.

戻り値の型:

Callable[..., MessageCommand]

パラメータ:

Objects

class discord.ApplicationCommand(func, **kwargs)[ソース]
パラメータ:

func (Callable)

is_on_cooldown(ctx)[ソース]

Checks whether the command is currently on cooldown.

注釈

This uses the current time instead of the interaction time.

パラメータ:

ctx (ApplicationContext) -- The invocation context to use when checking the command's cooldown status.

戻り値:

A boolean indicating if the command is on cooldown.

戻り値の型:

bool

reset_cooldown(ctx)[ソース]

Resets the cooldown on this command.

パラメータ:

ctx (ApplicationContext) -- The invocation context to reset the cooldown under.

戻り値の型:

None

get_cooldown_retry_after(ctx)[ソース]

Retrieves the amount of seconds before this command can be tried again.

注釈

This uses the current time instead of the interaction time.

パラメータ:

ctx (ApplicationContext) -- The invocation context to retrieve the cooldown from.

戻り値:

The amount of time left on this command's cooldown in seconds. If this is 0.0 then the command isn't on cooldown.

戻り値の型:

float

error(coro)[ソース]

A decorator that registers a coroutine as a local error handler.

A local error handler is an on_command_error() event limited to a single command. However, the on_command_error() is still invoked afterwards as the catch-all.

パラメータ:

coro (coroutine) -- The coroutine to register as the local error handler.

例外:

TypeError -- The coroutine passed is not actually a coroutine.

has_error_handler()[ソース]

Checks whether the command has an error handler registered.

戻り値の型:

bool

before_invoke(coro)[ソース]

A decorator that registers a coroutine as a pre-invoke hook. A pre-invoke hook is called directly before the command is called. This makes it a useful function to set up database connections or any type of set up required.

This pre-invoke hook takes a sole parameter, an ApplicationContext. See Bot.before_invoke() for more info.

パラメータ:

coro (coroutine) -- The coroutine to register as the pre-invoke hook.

例外:

TypeError -- The coroutine passed is not actually a coroutine.

after_invoke(coro)[ソース]

A decorator that registers a coroutine as a post-invoke hook. A post-invoke hook is called directly after the command is called. This makes it a useful function to clean-up database connections or any type of clean up required.

This post-invoke hook takes a sole parameter, an ApplicationContext. See Bot.after_invoke() for more info.

パラメータ:

coro (coroutine) -- The coroutine to register as the post-invoke hook.

例外:

TypeError -- The coroutine passed is not actually a coroutine.

property full_parent_name: str

Retrieves the fully qualified parent command name.

This the base command name required to execute it. For example, in /one two three the parent name would be one two.

property qualified_name: str

Retrieves the fully qualified command name.

This is the full parent name with the command name as well. For example, in /one two three the qualified name would be one two three.

property qualified_id: int

Retrieves the fully qualified command ID.

This is the root parent ID. For example, in /one two three the qualified ID would return one.id.

class discord.SlashCommand(func, *args, **kwargs)[ソース]

A class that implements the protocol for a slash command.

These are not created manually, instead they are created via the decorator or functional interface.

Added in version 2.0.

name

The name of the command.

Type:

str

callback

The coroutine that is executed when the command is called.

Type:

coroutine

description

The description for the command.

Type:

Optional[str]

guild_ids

The ids of the guilds where this command will be registered.

Type:

Optional[List[int]]

options

The parameters for this command.

Type:

List[Option]

parent

The parent group that this command belongs to. None if there isn't one.

Type:

Optional[SlashCommandGroup]

mention

Returns a string that allows you to mention the slash command.

Type:

str

guild_only

Whether the command should only be usable inside a guild.

バージョン 2.6 で非推奨: Use the contexts parameter instead.

Type:

bool

nsfw

Whether the command should be restricted to 18+ channels and users. Apps intending to be listed in the App Directory cannot have NSFW commands.

Type:

bool

default_member_permissions

The default permissions a member needs to be able to run the command.

Type:

Permissions

cog

The cog that this command belongs to. None if there isn't one.

Type:

Optional[Cog]

checks

A list of predicates that verifies if the command could be executed with the given ApplicationContext as the sole parameter. If an exception is necessary to be thrown to signal failure, then one inherited from ApplicationCommandError should be used. Note that if the checks fail then CheckFailure exception is raised to the on_application_command_error() event.

Type:

List[Callable[[ApplicationContext], bool]]

cooldown

The cooldown applied when the command is invoked. None if the command doesn't have a cooldown.

Type:

Optional[Cooldown]

name_localizations

The name localizations for this command. The values of this should be "locale": "name". See here for a list of valid locales.

Type:

Dict[str, str]

description_localizations

The description localizations for this command. The values of this should be "locale": "description". See here for a list of valid locales.

Type:

Dict[str, str]

integration_types

The type of installation this command should be available to. For instance, if set to IntegrationType.user_install, the command will only be available to users with the application installed on their account. Unapplicable for guild commands.

Type:

Set[IntegrationType]

contexts

The location where this command can be used. Cannot be set if this is a guild command.

Type:

Set[InteractionContextType]

パラメータ:

func (Callable)

copy()[ソース]

Creates a copy of this command.

戻り値:

A new instance of this command.

戻り値の型:

SlashCommand

class discord.SlashCommandGroup(name, description=None, guild_ids=None, parent=None, cooldown=None, max_concurrency=None, **kwargs)[ソース]

A class that implements the protocol for a slash command group.

These can be created manually, but they should be created via the decorator or functional interface.

name

The name of the command.

Type:

str

description

The description for the command.

Type:

Optional[str]

guild_ids

The ids of the guilds where this command will be registered.

Type:

Optional[List[int]]

parent

The parent group that this group belongs to. None if there isn't one.

Type:

Optional[SlashCommandGroup]

guild_only

Whether the command should only be usable inside a guild.

バージョン 2.6 で非推奨: Use the contexts parameter instead.

Type:

bool

nsfw

Whether the command should be restricted to 18+ channels and users. Apps intending to be listed in the App Directory cannot have NSFW commands.

Type:

bool

default_member_permissions

The default permissions a member needs to be able to run the command.

Type:

Permissions

checks

A list of predicates that verifies if the command could be executed with the given ApplicationContext as the sole parameter. If an exception is necessary to be thrown to signal failure, then one inherited from ApplicationCommandError should be used. Note that if the checks fail then CheckFailure exception is raised to the on_application_command_error() event.

Type:

List[Callable[[ApplicationContext], bool]]

name_localizations

The name localizations for this command. The values of this should be "locale": "name". See here for a list of valid locales.

Type:

Dict[str, str]

description_localizations

The description localizations for this command. The values of this should be "locale": "description". See here for a list of valid locales.

Type:

Dict[str, str]

integration_types

The type of installation this command should be available to. For instance, if set to IntegrationType.user_install, the command will only be available to users with the application installed on their account. Unapplicable for guild commands.

Type:

Set[IntegrationType]

contexts

The location where this command can be used. Unapplicable for guild commands.

Type:

Set[InteractionContextType]

パラメータ:
command(cls=<class 'discord.commands.core.SlashCommand'>, **kwargs)[ソース]

A shortcut decorator for adding a subcommand to this slash command group.

戻り値:

A decorator that converts the provided function into a SlashCommand, adds it to this group, then returns it.

戻り値の型:

Callable[[Callable], SlashCommand]

パラメータ:

cls (type[TypeVar(T)])

create_subgroup(name, description=None, guild_ids=None, **kwargs)[ソース]

Creates a new subgroup under this slash command group.

パラメータ:
  • name (str) -- The name of the group to create.

  • description (str | None) -- The description of the group to create.

  • guild_ids (list[int] | None) -- A list of the IDs of each guild this group should be added to, making it a guild command. This will be a global command if None is passed.

  • guild_only (bool) -- Whether the command should only be usable inside a guild.

  • 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.

  • checks (List[Callable[[ApplicationContext], bool]]) -- A list of predicates that verifies if the command could be executed with the given ApplicationContext as the sole parameter. If an exception is necessary to be thrown to signal failure, then one inherited from ApplicationCommandError should be used. Note that if the checks fail then CheckFailure exception is raised to the on_application_command_error() event.

  • name_localizations (Dict[str, str]) --

    The name localizations for this command. The values of this should be "locale": "name". See here for a list of valid locales.

  • description_localizations (Dict[str, str]) --

    The description localizations for this command. The values of this should be "locale": "description". See here for a list of valid locales.

戻り値:

The slash command group that was created.

戻り値の型:

SlashCommandGroup

subgroup(name=None, description=None, guild_ids=None)[ソース]

A shortcut decorator that initializes the provided subclass of SlashCommandGroup as a subgroup.

Added in version 2.0.

パラメータ:
  • name (str | None) -- The name of the group to create. This will resolve to the name of the decorated class if None is passed.

  • description (str | None) -- The description of the group to create.

  • guild_ids (list[int] | None) -- A list of the IDs of each guild this group should be added to, making it a guild command. This will be a global command if None is passed.

戻り値:

The slash command group that was created.

戻り値の型:

Callable[[type[SlashCommandGroup]], SlashCommandGroup]

walk_commands()[ソース]

An iterator that recursively walks through all slash commands and groups in this group.

列挙:

SlashCommand | SlashCommandGroup -- A nested slash command or slash command group from the group.

戻り値の型:

Generator[SlashCommand | SlashCommandGroup, None, None]

copy()[ソース]

Creates a copy of this command group.

戻り値:

A new instance of this command group.

戻り値の型:

SlashCommandGroup

class discord.UserCommand(func, *args, **kwargs)[ソース]

A class that implements the protocol for user context menu commands.

These are not created manually, instead they are created via the decorator or functional interface.

name

The name of the command.

Type:

str

callback

The coroutine that is executed when the command is called.

Type:

coroutine

guild_ids

The ids of the guilds where this command will be registered.

Type:

Optional[List[int]]

guild_only

Whether the command should only be usable inside a guild.

バージョン 2.6 で非推奨: Use the contexts parameter instead.

Type:

bool

nsfw

Whether the command should be restricted to 18+ channels and users. Apps intending to be listed in the App Directory cannot have NSFW commands.

Type:

bool

default_member_permissions

The default permissions a member needs to be able to run the command.

Type:

Permissions

cog

The cog that this command belongs to. None if there isn't one.

Type:

Optional[Cog]

checks

A list of predicates that verifies if the command could be executed with the given ApplicationContext as the sole parameter. If an exception is necessary to be thrown to signal failure, then one inherited from ApplicationCommandError should be used. Note that if the checks fail then CheckFailure exception is raised to the on_application_command_error() event.

Type:

List[Callable[[ApplicationContext], bool]]

cooldown

The cooldown applied when the command is invoked. None if the command doesn't have a cooldown.

Type:

Optional[Cooldown]

name_localizations

The name localizations for this command. The values of this should be "locale": "name". See here for a list of valid locales.

Type:

Dict[str, str]

integration_types

The installation contexts where this command is available. Unapplicable for guild commands.

Type:

Set[IntegrationType]

contexts

The interaction contexts where this command is available. Unapplicable for guild commands.

Type:

Set[InteractionContextType]

パラメータ:

func (Callable)

copy()[ソース]

Creates a copy of this command.

戻り値:

A new instance of this command.

戻り値の型:

UserCommand

class discord.MessageCommand(func, *args, **kwargs)[ソース]

A class that implements the protocol for message context menu commands.

These are not created manually, instead they are created via the decorator or functional interface.

name

The name of the command.

Type:

str

callback

The coroutine that is executed when the command is called.

Type:

coroutine

guild_ids

The ids of the guilds where this command will be registered.

Type:

Optional[List[int]]

guild_only

Whether the command should only be usable inside a guild.

バージョン 2.6 で非推奨: Use the contexts parameter instead.

Type:

bool

nsfw

Whether the command should be restricted to 18+ channels and users. Apps intending to be listed in the App Directory cannot have NSFW commands.

Type:

bool

default_member_permissions

The default permissions a member needs to be able to run the command.

Type:

Permissions

cog

The cog that this command belongs to. None if there isn't one.

Type:

Optional[Cog]

checks

A list of predicates that verifies if the command could be executed with the given ApplicationContext as the sole parameter. If an exception is necessary to be thrown to signal failure, then one inherited from ApplicationCommandError should be used. Note that if the checks fail then CheckFailure exception is raised to the on_application_command_error() event.

Type:

List[Callable[[ApplicationContext], bool]]

cooldown

The cooldown applied when the command is invoked. None if the command doesn't have a cooldown.

Type:

Optional[Cooldown]

name_localizations

The name localizations for this command. The values of this should be "locale": "name". See here for a list of valid locales.

Type:

Dict[str, str]

integration_types

The installation contexts where this command is available. Unapplicable for guild commands.

Type:

Set[IntegrationType]

contexts

The interaction contexts where this command is available. Unapplicable for guild commands.

Type:

Set[InteractionContextType]

パラメータ:

func (Callable)

copy()[ソース]

Creates a copy of this command.

戻り値:

A new instance of this command.

戻り値の型:

MessageCommand

Options

Shortcut Decorators

@discord.commands.option(name, input_type=None, **kwargs)[ソース]

A decorator that can be used instead of typehinting Option.

Added in version 2.0.

discord.commands.parameter_name

The name of the target function parameter this option is mapped to. This allows you to have a separate UI name and parameter name.

Type:

str

Objects

class discord.Option(input_type=<class 'str'>, /, description=None, **kwargs)[ソース]

Represents a selectable option for a slash command.

input_type

The type of input that is expected for this option. This can be a SlashCommandOptionType, an associated class, a channel type, a Converter, a converter class or an enum.Enum. If a enum.Enum is used and it has up to 25 values, choices will be automatically filled. If the enum.Enum has more than 25 values, autocomplete will be implemented with discord.utils.basic_autocomplete() instead.

Type:

Union[Type[str], Type[bool], Type[int], Type[float], Type[abc.GuildChannel], Type[Thread], Type[Member], Type[User], Type[Attachment], Type[Role], Type[abc.Mentionable], SlashCommandOptionType, Type[ext.commands.Converter], Type[enums.Enum], Type[Enum]]

name

The name of this option visible in the UI. Inherits from the variable name if not provided as a parameter.

Type:

str

description

The description of this option. Must be 100 characters or fewer. If input_type is a enum.Enum and description is not specified, input_type's docstring will be used.

Type:

Optional[str]

choices

The list of available choices for this option. Can be a list of values or OptionChoice objects (which represent a name:value pair). If provided, the input from the user must match one of the choices in the list.

Type:

Optional[List[Union[Any, OptionChoice]]]

required

Whether this option is required.

Type:

Optional[bool]

default

The default value for this option. If provided, required will be considered False.

Type:

Optional[Any]

min_value

The minimum value that can be entered. Only applies to Options with an input_type of int or float.

Type:

Optional[int]

max_value

The maximum value that can be entered. Only applies to Options with an input_type of int or float.

Type:

Optional[int]

min_length

The minimum length of the string that can be entered. Must be between 0 and 6000 (inclusive). Only applies to Options with an input_type of str.

Type:

Optional[int]

max_length

The maximum length of the string that can be entered. Must be between 1 and 6000 (inclusive). Only applies to Options with an input_type of str.

Type:

Optional[int]

channel_types

A list of channel types that can be selected in this option. Only applies to Options with an input_type of discord.SlashCommandOptionType.channel. If this argument is used, input_type will be ignored.

Type:

list[discord.ChannelType] | None

name_localizations

The name localizations for this option. The values of this should be "locale": "name". See here for a list of valid locales.

Type:

Dict[str, str]

description_localizations

The description localizations for this option. The values of this should be "locale": "description". See here for a list of valid locales.

Type:

Dict[str, str]

サンプル

Basic usage:

@bot.slash_command(guild_ids=[...])
async def hello(
    ctx: discord.ApplicationContext,
    name: Option(str, "Enter your name"),
    age: Option(int, "Enter your age", min_value=1, max_value=99, default=18)
    # passing the default value makes an argument optional
    # you also can create optional argument using:
    # age: Option(int, "Enter your age") = 18
):
    await ctx.respond(f"Hello! Your name is {name} and you are {age} years old.")

Added in version 2.0.

パラメータ:
property autocomplete: Callable[[AutocompleteContext], Iterable[OptionChoice] | Iterable[str] | Iterable[int] | Iterable[float] | Awaitable[Iterable[OptionChoice] | Iterable[str] | Iterable[int] | Iterable[float]]] | Callable[[Cog, AutocompleteContext], Iterable[OptionChoice] | Iterable[str] | Iterable[int] | Iterable[float] | Awaitable[Iterable[OptionChoice] | Iterable[str] | Iterable[int] | Iterable[float]]] | Callable[[AutocompleteContext, Any], Iterable[OptionChoice] | Iterable[str] | Iterable[int] | Iterable[float] | Awaitable[Iterable[OptionChoice] | Iterable[str] | Iterable[int] | Iterable[float]]] | Callable[[Cog, AutocompleteContext, Any], Iterable[OptionChoice] | Iterable[str] | Iterable[int] | Iterable[float] | Awaitable[Iterable[OptionChoice] | Iterable[str] | Iterable[int] | Iterable[float]]] | None

The autocomplete handler for the option. Accepts a callable (sync or async) that takes a single required argument of AutocompleteContext or two arguments of discord.Cog (being the command's cog) and AutocompleteContext. The callable must return an iterable of str or OptionChoice. Alternatively, discord.utils.basic_autocomplete() may be used in place of the callable.

戻り値:

  • Optional[AutocompleteFunction]

  • .. versionchanged:: 2.7

  • .. note:: -- Does not validate the input value against the autocomplete results.

class discord.ThreadOption(thread_type)[ソース]

Represents a class that can be passed as the input_type for an Option class.

Added in version 2.0.

パラメータ:

thread_type (Literal['public', 'private', 'news']) -- The thread type to expect for this options input.

class discord.OptionChoice(name, value=None, name_localizations=...)[ソース]

Represents a name:value pairing for a selected Option.

Added in version 2.0.

name

The name of the choice. Shown in the UI when selecting an option.

Type:

str

value

The value of the choice. If not provided, will use the value of name.

Type:

Optional[Union[str, int, float]]

name_localizations

The name localizations for this choice. The values of this should be "locale": "name". See here for a list of valid locales.

Type:

Dict[str, str]

パラメータ:

Context Objects

class discord.ApplicationContext(bot, interaction)[ソース]

Represents a Discord application command interaction context.

This class is not created manually and is instead passed to application commands as the first parameter.

Added in version 2.0.

bot

The bot that the command belongs to.

Type:

Bot

interaction

The interaction object that invoked the command.

Type:

Interaction

パラメータ:
await invoke(command, /, *args, **kwargs)[ソース]

This function is a coroutine.

Calls a command with the arguments given. This is useful if you want to just call the callback that a ApplicationCommand holds internally.

注釈

This does not handle converters, checks, cooldowns, pre-invoke, or after-invoke hooks in any matter. It calls the internal callback directly as-if it was a regular function. You must take care in passing the proper arguments when using this function.

パラメータ:
  • command (ApplicationCommand[TypeVar(CogT, bound= Cog), ParamSpec(P, bound= None), TypeVar(T)]) -- The command that is going to be called.

  • *args (ParamSpecArgs) -- The arguments to use.

  • **kwargs (ParamSpecKwargs) -- The keyword arguments to use.

例外:

TypeError -- The command argument to invoke is missing.

戻り値の型:

TypeVar(T)

property command: ApplicationCommand | None

The command that this context belongs to.

property channel: VoiceChannel | StageChannel | TextChannel | ForumChannel | CategoryChannel | Thread | DMChannel | GroupChannel | PartialMessageable | None

Union[abc.GuildChannel, PartialMessageable, Thread]: Returns the channel associated with this context's command. Shorthand for Interaction.channel.

property channel_id: int | None

Returns the ID of the channel associated with this context's command. Shorthand for Interaction.channel_id.

property guild: Guild | None

Returns the guild associated with this context's command. Shorthand for Interaction.guild.

property guild_id: int | None

Returns the ID of the guild associated with this context's command. Shorthand for Interaction.guild_id.

property locale: str | None

Returns the locale of the guild associated with this context's command. Shorthand for Interaction.locale.

property guild_locale: str | None

Returns the locale of the guild associated with this context's command. Shorthand for Interaction.guild_locale.

property me: Member | ClientUser | None

Union[Member, ClientUser]: Similar to Guild.me except it may return the ClientUser in private message message contexts, or when Intents.guilds() is absent.

property message: Message | None

Returns the message sent with this context's command. Shorthand for Interaction.message, if applicable.

property user: Member | User

Returns the user that sent this context's command. Shorthand for Interaction.user.

property author: Member | User

Returns the user that sent this context's command. Shorthand for Interaction.user.

property voice_client: VoiceClient | None

Returns the voice client associated with this context's command. Shorthand for Interaction.guild.voice_client, if applicable.

property response: InteractionResponse

Returns the response object associated with this context's command. Shorthand for Interaction.response.

property selected_options: list[dict[str, Any]] | None

The options and values that were selected by the user when sending the command.

戻り値:

A dictionary containing the options and values that were selected by the user when the command was processed, if applicable. Returns None if the command has not yet been invoked, or if there are no options defined for that command.

戻り値の型:

Optional[List[Dict[str, Any]]]

property unselected_options: list[Option] | None

The options that were not provided by the user when sending the command.

戻り値:

A list of Option objects (if any) that were not selected by the user when the command was processed. Returns None if there are no options defined for that command.

戻り値の型:

Optional[List[Option]]

property attachment_size_limit: int

Returns the attachment size limit associated with this context's interaction. Shorthand for Interaction.attachment_size_limit.

property send_modal: Callable[[...], Awaitable[Interaction]]

This function is a coroutine. Responds to this interaction by sending a modal dialog. This cannot be used to respond to another modal dialog submission.

パラメータ:

modal (discord.ui.BaseModal) -- The modal dialog to display to the user.

例外:
await respond(*args, **kwargs)[ソース]

This function is a coroutine.

Sends either a response or a message using the followup webhook determined by whether the interaction has been responded to or not.

パラメータ:
  • content (Optional[str]) -- The content of the message to send.

  • embeds (List[Embed]) -- A list of embeds to send with the content. Maximum of 10. This cannot be mixed with the embed parameter.

  • embed (Embed) -- The rich embed for the content to send. This cannot be mixed with embeds parameter.

  • tts (bool) -- Indicates if the message should be sent using text-to-speech.

  • view (discord.ui.BaseView) -- The view to send with the message.

  • ephemeral (bool) -- Indicates if the message should only be visible to the user who started the interaction. If a view is sent with an ephemeral message, and it has no timeout set then the timeout is set to 15 minutes.

  • allowed_mentions (AllowedMentions) -- Controls the mentions being processed in this message. See abc.Messageable.send() for more information.

  • delete_after (float) -- If provided, the number of seconds to wait in the background before deleting the message we just sent.

  • file (File) -- The file to upload.

  • files (List[File]) -- A list of files to upload. Must be a maximum of 10.

  • poll (Poll) --

    The poll to send.

    Added in version 2.6.

  • silent (bool) --

    Whether to suppress push and desktop notifications for the message.

    Added in version 2.8.

  • suppress_embeds (bool) --

    Whether to suppress embeds for the message.

    Added in version 2.8.

戻り値:

The response, its type depending on whether it's an interaction response or a followup.

戻り値の型:

Interaction | WebhookMessage

property send_response: Callable[[...], Awaitable[Interaction]]

This function is a coroutine.

Responds to this interaction by sending a message.

パラメータ:
  • content (Optional[str]) -- The content of the message to send.

  • embeds (List[Embed]) -- A list of embeds to send with the content. Maximum of 10. This cannot be mixed with the embed parameter.

  • embed (Embed) -- The rich embed for the content to send. This cannot be mixed with embeds parameter.

  • tts (bool) -- Indicates if the message should be sent using text-to-speech.

  • view (discord.ui.BaseView) -- The view to send with the message.

  • ephemeral (bool) -- Indicates if the message should only be visible to the user who started the interaction. If a view is sent with an ephemeral message, and it has no timeout set then the timeout is set to 15 minutes.

  • allowed_mentions (AllowedMentions) -- Controls the mentions being processed in this message. See abc.Messageable.send() for more information.

  • delete_after (float) -- If provided, the number of seconds to wait in the background before deleting the message we just sent.

  • file (File) -- The file to upload.

  • files (List[File]) -- A list of files to upload. Must be a maximum of 10.

  • poll (Poll) --

    The poll to send.

    Added in version 2.6.

  • silent (bool) --

    Whether to suppress push and desktop notifications for the message.

    Added in version 2.8.

  • suppress_embeds (bool) --

    Whether to suppress embeds for the message.

    Added in version 2.8.

戻り値:

The interaction object associated with the sent message.

戻り値の型:

Interaction

例外:
  • HTTPException -- Sending the message failed.

  • TypeError -- You specified both embed and embeds, or sent content or embeds with V2 components.

  • ValueError -- The length of embeds was invalid.

  • InteractionResponded -- This interaction has already been responded to before.

property send_followup: Callable[[...], Awaitable[WebhookMessage]]

This function is a coroutine.

Sends a message using the webhook.

The content must be a type that can convert to a string through str(content).

To upload a single file, the file parameter should be used with a single File object.

If the embed parameter is provided, it must be of type Embed and it must be a rich embed type. You cannot mix the embed parameter with the embeds parameter, which must be a list of Embed objects to send.

パラメータ:
  • content (str) -- The content of the message to send.

  • wait (bool) -- Whether the server should wait before sending a response. This essentially means that the return type of this function changes from None to a WebhookMessage if set to True. If the type of webhook is WebhookType.application then this is always set to True.

  • username (str) -- The username to send with this message. If no username is provided then the default username for the webhook is used.

  • avatar_url (str) -- The avatar URL to send with this message. If no avatar URL is provided then the default avatar for the webhook is used. If this is not a string then it is explicitly cast using str.

  • tts (bool) -- Indicates if the message should be sent using text-to-speech.

  • ephemeral (bool) --

    Indicates if the message should only be visible to the user. This is only available to WebhookType.application webhooks. If a view is sent with an ephemeral message, and it has no timeout set then the timeout is set to 15 minutes.

    Added in version 2.0.

  • file (File) -- The file to upload. This cannot be mixed with files parameter.

  • files (List[File]) -- A list of files to send with the content. This cannot be mixed with the file parameter.

  • embed (Embed) -- The rich embed for the content to send. This cannot be mixed with embeds parameter.

  • embeds (List[Embed]) -- A list of embeds to send with the content. Maximum of 10. This cannot be mixed with the embed parameter.

  • allowed_mentions (AllowedMentions) --

    Controls the mentions being processed in this message.

    Added in version 1.4.

  • view (discord.ui.BaseView) --

    The view to send with the message. You can only send a view if this webhook is not partial and has state attached. A webhook has state attached if the webhook is managed by the library.

    Added in version 2.0.

  • thread (Snowflake) --

    The thread to send this webhook to.

    Added in version 2.0.

  • thread_name (str) --

    The name of the thread to create. Only works for forum channels.

    Added in version 2.0.

  • applied_tags (List[Snowflake]) --

    A list of tags to apply to the message. Only works for threads.

    Added in version 2.5.

  • delete_after (float) -- If provided, the number of seconds to wait in the background before deleting the message we just sent.

  • poll (Poll) --

    The poll to send.

    Added in version 2.6.

  • silent (bool) --

    Whether to suppress push and desktop notifications for the message.

    Added in version 2.8.

  • suppress_embeds (bool) --

    Whether to suppress embeds for the message.

    Added in version 2.8.

戻り値:

If wait is True then the message that was sent, otherwise None.

戻り値の型:

Optional[WebhookMessage]

例外:
  • HTTPException -- Sending the message failed.

  • NotFound -- This webhook was not found.

  • Forbidden -- The authorization token for the webhook is incorrect.

  • TypeError -- You specified both embed and embeds or file and files.

  • ValueError -- The length of embeds was invalid.

  • InvalidArgument -- Either there was no token associated with this webhook, ephemeral was passed with the improper webhook type, there was no state attached with this webhook when giving it a dispatchable view, you specified both thread_name and thread, or applied_tags was passed with neither thread_name nor thread specified.

property defer: Callable[[...], Awaitable[None]]

This function is a coroutine.

Defers the interaction response.

This is typically used when the interaction is acknowledged and a secondary action will be done later.

This can only be used with the following interaction types:

注釈

The follow-up response will also be non-ephemeral if the ephemeral argument is False, and ephemeral if True.

パラメータ:
例外:
property followup: Webhook

Returns the followup webhook for followup interactions.

await delete(*, delay=None)[ソース]

This function is a coroutine.

Deletes the original interaction response message.

This is a higher level interface to Interaction.delete_original_response().

パラメータ:

delay (float | None) -- If provided, the number of seconds to wait before deleting the message.

例外:
  • HTTPException -- Deleting the message failed.

  • Forbidden -- You do not have proper permissions to delete the message.

戻り値の型:

None

property edit: Callable[[...], Awaitable[InteractionMessage]]

This function is a coroutine.

Edits the original interaction response message.

This is a lower level interface to InteractionMessage.edit() in case you do not want to fetch the message and save an HTTP request.

This method is also the only way to edit the original message if the message sent was ephemeral.

パラメータ:
  • content (Optional[str]) -- The content to edit the message with or None to clear it.

  • embeds (List[Embed]) -- A list of embeds to edit the message with.

  • embed (Optional[Embed]) -- The embed to edit the message with. None suppresses the embeds. This should not be mixed with the embeds parameter.

  • file (File) -- The file to upload. This cannot be mixed with files parameter.

  • files (List[File]) -- A list of files to send with the content. This cannot be mixed with the file parameter.

  • attachments (List[Attachment]) -- A list of attachments to keep in the message. If [] is passed then all attachments are removed.

  • allowed_mentions (AllowedMentions) -- Controls the mentions being processed in this message. See abc.Messageable.send() for more information.

  • view (Optional[BaseView]) -- The updated view to update this message with. If None is passed then the view is removed.

  • delete_after (Optional[float]) -- If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.

  • suppress (bool) --

    Whether to suppress embeds for the message.

    バージョン 2.8 で非推奨.

  • suppress_embeds (bool) --

    Whether to suppress embeds for the message.

    Added in version 2.8.

戻り値:

The newly edited message.

戻り値の型:

InteractionMessage

例外:
  • HTTPException -- Editing the message failed.

  • Forbidden -- Edited a message that is not yours.

  • TypeError -- You specified both embed and embeds or file and files

  • ValueError -- The length of embeds was invalid.

property cog: Cog | None

Returns the cog associated with this context's command. None if it does not exist.

is_guild_authorised()[ソース]

bool: Checks if the invoked command is guild-installed. This is a shortcut for Interaction.is_guild_authorised().

There is an alias for this called is_guild_authorized().

Added in version 2.7.

戻り値の型:

bool

is_user_authorised()[ソース]

bool: Checks if the invoked command is user-installed. This is a shortcut for Interaction.is_user_authorised().

There is an alias for this called is_user_authorized().

Added in version 2.7.

戻り値の型:

bool

is_guild_authorized()[ソース]

bool: An alias for is_guild_authorised().

Added in version 2.7.

戻り値の型:

bool

is_user_authorized()[ソース]

bool: An alias for is_user_authorised().

Added in version 2.7.

戻り値の型:

bool

class discord.AutocompleteContext(bot, interaction)[ソース]

Represents context for a slash command's option autocomplete.

This class is not created manually and is instead passed to an Option's autocomplete callback.

Added in version 2.0.

bot

The bot that the command belongs to.

Type:

Bot

interaction

The interaction object that invoked the autocomplete.

Type:

Interaction

focused

The option the user is currently typing.

Type:

Option

value

The content of the focused option.

Type:

str

options

A name to value mapping of the options that the user has selected before this option.

Type:

Dict[str, Any]

パラメータ:
property cog: Cog | None

Returns the cog associated with this context's command. None if it does not exist.

property command: ApplicationCommand | None

The command that this context belongs to.