API Reference¶
The reference manual that follows details the API of Pycord’s bridge command extension module.
Примечание
Using the prefixed command version (which uses the ext.commands extension) of bridge
commands in guilds requires Intents.message_context to be enabled.
Bots¶
Bot¶
- class discord.ext.bridge.Bot(command_prefix=<function when_mentioned>, help_command=..., **options)[исходный код]¶
Represents a discord bot, with support for cross-compatibility between command types.
This class is a subclass of
ext.commands.Botand as a result anything that you can do with aext.commands.Botyou can do with this bot.Добавлено в версии 2.0.
- Параметры:
- add_bridge_command(command)¶
Takes a
BridgeCommandand adds both a slash and traditional (prefix-based) version of the command to the bot.- Параметры:
command (
BridgeCommand)
- @bridge_command¶
A shortcut decorator that invokes
bridge_command()and adds it to the internal command list viaadd_bridge_command().- Результат:
A decorator that converts the provided method into an
BridgeCommand, adds both a slash and traditional (prefix-based) version of the command to the bot, and returns theBridgeCommand.- Тип результата:
Callable[…,
BridgeCommand]
- @bridge_group¶
A decorator that is used to wrap a function as a bridge command group.
- Параметры:
kwargs (Optional[Dict[
str, Any]]) – Keyword arguments that are directly passed to the respective command constructors. (SlashCommandGroupandext.commands.Group)
AutoShardedBot¶
- class discord.ext.bridge.AutoShardedBot(command_prefix=<function when_mentioned>, help_command=..., **options)[исходный код]¶
This is similar to
Botexcept that it is inherited fromext.commands.AutoShardedBotinstead.Добавлено в версии 2.0.
Event Reference¶
These events function similar to the regular events, except they are custom to the bridge extension module.
- discord.ext.bridge.on_bridge_command_error(ctx, error)¶
An error handler that is called when an error is raised inside a command either through user input error, check failure, or an error in your own code.
- Параметры:
ctx (
Context) – The invocation context.error (
CommandErrorderived) – The error that was raised.
Commands¶
BridgeCommand¶
- defadd_to
- @after_invoke
- @before_invoke
- @error
- class discord.ext.bridge.BridgeCommand(callback, **kwargs)[исходный код]¶
Compatibility class between prefixed-based commands and slash commands.
- Параметры:
callback (Callable[[
BridgeContext, …], Awaitable[Any]]) – The callback to invoke when the command is executed. The first argument will be aBridgeContext, and any additional arguments will be passed to the callback. This callback must be a coroutine.parent (Optional[
BridgeCommandGroup]:) – Parent of the BridgeCommand.kwargs (Optional[Dict[
str, Any]]) – Keyword arguments that are directly passed to the respective command constructors. (SlashCommandandext.commands.Command)
- slash_variant¶
The slash command version of this bridge command.
- Type:
- ext_variant¶
The prefix-based version of this bridge command.
- Type:
- property name_localizations: dict[str, str] | None¶
- Returns name_localizations from
slash_variant You can edit/set name_localizations directly with
bridge_command.name_localizations["en-UK"] = ... # or any other locale # or bridge_command.name_localizations = {"en-UK": ..., "fr-FR": ...}
- Returns name_localizations from
- property description_localizations: dict[str, str] | None¶
- Returns description_localizations from
slash_variant You can edit/set description_localizations directly with
bridge_command.description_localizations["en-UK"] = ... # or any other locale # or bridge_command.description_localizations = {"en-UK": ..., "fr-FR": ...}
- Returns description_localizations from
- add_to(bot)[исходный код]¶
Adds the command to a bot. This method is inherited by
BridgeCommandGroup.
- error(coro)[исходный код]¶
A decorator that registers a coroutine as a local error handler.
This error handler is limited to the command it is defined to. However, higher scope handlers (per-cog and global) are still invoked afterwards as a catch-all. This handler also functions as the handler for both the prefixed and slash versions of the command.
This error handler takes two parameters, a
BridgeContextand aDiscordException.
- before_invoke(coro)[исходный код]¶
A decorator that registers a coroutine as a pre-invoke hook.
This hook is called directly before the command is called, making it useful for any sort of set up required. This hook is called for both the prefixed and slash versions of the command.
This pre-invoke hook takes a sole parameter, a
BridgeContext.
- after_invoke(coro)[исходный код]¶
A decorator that registers a coroutine as a post-invoke hook.
This hook is called directly after the command is called, making it useful for any sort of clean up required. This hook is called for both the prefixed and slash versions of the command.
This post-invoke hook takes a sole parameter, a
BridgeContext.
BridgeCommandGroup¶
- @command
- defwalk_commands
- class discord.ext.bridge.BridgeCommandGroup(callback, *args, **kwargs)[исходный код]¶
Compatibility class between prefixed-based commands and slash commands.
- Параметры:
callback (Callable[[
BridgeContext, …], Awaitable[Any]]) – The callback to invoke when the command is executed. The first argument will be aBridgeContext, and any additional arguments will be passed to the callback. This callback must be a coroutine.kwargs (Optional[Dict[
str, Any]]) – Keyword arguments that are directly passed to the respective command constructors. (SlashCommandandext.commands.Command)
- slash_variant¶
The slash command version of this command group.
- Type:
- ext_variant¶
The prefix-based version of this command group.
- Type:
- subcommands¶
List of bridge commands in this group
- Type:
List[
BridgeCommand]
- mapped¶
If
map_to()is used, the mapped slash command.- Type:
Optional[
SlashCommand]
- walk_commands()[исходный код]¶
An iterator that recursively walks through all the bridge group’s subcommands.
- Yields:
BridgeCommand– A bridge command of this bridge group.
- command(*args, **kwargs)[исходный код]¶
A decorator to register a function as a subcommand.
- Параметры:
kwargs (Optional[Dict[
str, Any]]) – Keyword arguments that are directly passed to the respective command constructors. (SlashCommandandext.commands.Command)
Decorators¶
- @bridge.bridge_command¶
A decorator that is used to wrap a function as a bridge command.
- Параметры:
kwargs (Optional[Dict[
str, Any]]) – Keyword arguments that are directly passed to the respective command constructors. (SlashCommandandext.commands.Command)
- @bridge.bridge_group¶
A decorator that is used to wrap a function as a bridge command group.
- Параметры:
kwargs (Optional[Dict[
str, Any]]) – Keyword arguments that are directly passed to the respective command constructors (SlashCommandGroupandext.commands.Group).
- @bridge.map_to¶
To be used with bridge command groups, map the main command to a slash subcommand.
- Параметры:
Пример
@bot.bridge_group() @bridge.map_to("show") async def config(ctx: BridgeContext): ... @config.command() async def toggle(ctx: BridgeContext): ...
Prefixed commands will not be affected, but slash commands will appear as:
/config show /config toggle
- @bridge.guild_only¶
Intended to work with
ApplicationCommandandBridgeCommand, adds acheck()that locks the command to only run in guilds, and also registers the command as guild only client-side (on discord).Basically a utility function that wraps both
discord.ext.commands.guild_only()anddiscord.commands.guild_only().
- @bridge.is_nsfw¶
Intended to work with
ApplicationCommandandBridgeCommand, adds acheck()that locks the command to only run in nsfw contexts, and also registers the command as nsfw client-side (on discord).Basically a utility function that wraps both
discord.ext.commands.is_nsfw()anddiscord.commands.is_nsfw().Предупреждение
In DMs, the prefixed-based command will always run as the user’s privacy settings cannot be checked directly.
- @bridge.has_permissions¶
Intended to work with
SlashCommandandBridgeCommand, adds acheck()that locks the command to be run by people with certain permissions inside guilds, and also registers the command as locked behind said permissions.Basically a utility function that wraps both
discord.ext.commands.has_permissions()anddiscord.commands.default_permissions().- Параметры:
**perms (
bool) – An argument list of permissions to check for.
Command Subclasses¶
- class discord.ext.bridge.BridgeExtCommand(*args: Any, **kwargs: Any)[исходный код]¶
A subclass of
ext.commands.Commandthat is used for bridge commands.
- class discord.ext.bridge.BridgeExtGroup(*args: Any, **kwargs: Any)[исходный код]¶
A subclass of
ext.commands.Groupthat is used for bridge commands.
- class discord.ext.bridge.BridgeSlashCommand(*args, **kwargs)[исходный код]¶
A subclass of
SlashCommandthat is used for bridge commands.
- class discord.ext.bridge.BridgeSlashGroup(*args, **kwargs)[исходный код]¶
A subclass of
SlashCommandGroupthat is used for bridge commands.
Context¶
BridgeContext¶
- class discord.ext.bridge.BridgeContext[исходный код]¶
The base context class for compatibility commands. This class is an abstract base class (also known as an
abc), which is subclassed byBridgeExtContextandBridgeApplicationContext. The methods in this class are meant to give parity between the two contexts, while still allowing for all of their functionality.When this is passed to a command, it will either be passed as
BridgeExtContext, orBridgeApplicationContext. Since they are two separate classes, it’s easy to use theBridgeContext.is_appattribute. to make different functionality for each context. For example, if you want to respond to a command with the command type that it was invoked with, you can do the following:@bot.bridge_command() async def example(ctx: BridgeContext): if ctx.is_app: command_type = "Application command" else: command_type = "Traditional (prefix-based) command" await ctx.send(f"This command was invoked with a(n) {command_type}.")
Добавлено в версии 2.0.
- invoke(**kwds)¶
Helper for @overload to raise when called.
- await respond(*args, **kwargs)[исходный код]¶
This function is a coroutine.
Responds to the command with the respective response type to the current context. In
BridgeExtContext, this will bereply()while inBridgeApplicationContext, this will berespond().- Тип результата:
- await reply(*args, **kwargs)[исходный код]¶
This function is a coroutine.
Alias for
respond().- Тип результата:
- await defer(*args, **kwargs)[исходный код]¶
This function is a coroutine.
Defers the command with the respective approach to the current context. In
BridgeExtContext, this will betrigger_typing()while inBridgeApplicationContext, this will bedefer.Примечание
There is no
trigger_typingalias for this method.trigger_typingwill always provide the same functionality across contexts.- Тип результата:
- await edit(*args, **kwargs)[исходный код]¶
This function is a coroutine.
Edits the original response message with the respective approach to the current context. In
BridgeExtContext, this will have a custom approach whererespond()caches the message to be edited here. InBridgeApplicationContext, this will beedit.- Тип результата:
- property is_app: bool¶
Whether the context is an
BridgeApplicationContextor not.
BridgeContext Subclasses¶
- class discord.ext.bridge.BridgeApplicationContext(*args, **kwargs)[исходный код]¶
The application context class for compatibility commands. This class is a subclass of
BridgeContextandApplicationContext. This class is meant to be used withBridgeCommand.Добавлено в версии 2.0.
- asyncdelete
- class discord.ext.bridge.BridgeExtContext(*args, **kwargs)[исходный код]¶
The ext.commands context class for compatibility commands. This class is a subclass of
BridgeContextandContext. This class is meant to be used withBridgeCommand.Добавлено в версии 2.0.
- await delete(*, delay=None, reason=None)[исходный код]¶
This function is a coroutine.
Deletes the original response message, if it exists.
- discord.ext.bridge.Context¶
Alias of
typing.Union[BridgeExtContext,BridgeApplicationContext] for typing convenience. псевдоним дляBridgeExtContext|BridgeApplicationContext
Options¶
Shortcut Decorators¶
- @discord.ext.bridge.bridge_option(name, input_type=None, **kwargs)[исходный код]¶
A decorator that can be used instead of typehinting
BridgeOption.Добавлено в версии 2.6.
Objects¶
- asyncconvert
- class discord.ext.bridge.BridgeOption(input_type, *args, **kwargs)[исходный код]¶
A subclass of
discord.Optionwhich represents a selectable slash command option and a prefixed command argument for bridge commands.- await convert(ctx, argument)[исходный код]¶
This function is a coroutine.
The method to override to do conversion logic.
If an error is found while converting, it is recommended to raise a
CommandErrorderived exception as it will properly propagate to the error handlers.- Параметры:
- Исключение:
.CommandError – A generic exception occurred when converting the argument.
.BadArgument – The converter failed to convert the argument.
- Тип результата: