API Reference

The reference manual that follows details the API of Pycord’s bridge command extension module.

Note

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=<default-help-command>, **options)

Represents a discord bot, with support for cross-compatibility between command types.

This class is a subclass of ext.commands.Bot and as a result anything that you can do with a ext.commands.Bot you can do with this bot.

New in version 2.0.

add_bridge_command()

Takes a BridgeCommand and adds both a slash and traditional (prefix-based) version of the command to the bot.

@bridge_command

A shortcut decorator that invokes bridge_command() and adds it to the internal command list via add_bridge_command().

Returns

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 the BridgeCommand.

Return type

Callable[…, BridgeCommand]

@bridge_group

A decorator that is used to wrap a function as a bridge command group.

Parameters

kwargs (Optional[Dict[str, Any]]) – Keyword arguments that are directly passed to the respective command constructors. (SlashCommandGroup and ext.commands.Group)

AutoShardedBot

class discord.ext.bridge.AutoShardedBot(command_prefix=<function when_mentioned>, help_command=<default-help-command>, **options)

This is similar to Bot except that it is inherited from ext.commands.AutoShardedBot instead.

New in version 2.0.

Commands

BridgeCommand

class discord.ext.bridge.BridgeCommand(callback, **kwargs)

Compatibility class between prefixed-based commands and slash commands.

slash_variant

The slash command version of this bridge command.

Type

BridgeSlashCommand

ext_variant

The prefix-based version of this bridge command.

Type

BridgeExtCommand

Parameters
  • callback (Callable[[BridgeContext, …], Awaitable[Any]]) – The callback to invoke when the command is executed. The first argument will be a BridgeContext, 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. (SlashCommand and ext.commands.Command)

property name_localizations

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": ...}
Type

Dict[str, str]

property description_localizations

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": ...}
Type

Dict[str, str]

add_to(bot)

Adds the command to a bot. This method is inherited by BridgeCommandGroup.

Parameters

bot (Union[Bot, AutoShardedBot]) – The bot to add the command to.

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 BridgeContext and a DiscordException.

Parameters

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

Raises

TypeError – The coroutine passed is not actually a coroutine.

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.

Parameters

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

Raises

TypeError – The coroutine passed is not actually a coroutine.

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.

Parameters

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

Raises

TypeError – The coroutine passed is not actually a coroutine.

@bridge.bridge_command

A decorator that is used to wrap a function as a bridge command.

Parameters

kwargs (Optional[Dict[str, Any]]) – Keyword arguments that are directly passed to the respective command constructors. (SlashCommand and ext.commands.Command)

BridgeCommandGroup

class discord.ext.bridge.BridgeCommandGroup(callback, *args, **kwargs)

Compatibility class between prefixed-based commands and slash commands.

Parameters
  • callback (Callable[[BridgeContext, …], Awaitable[Any]]) – The callback to invoke when the command is executed. The first argument will be a BridgeContext, 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. (SlashCommand and ext.commands.Command)

slash_variant

The slash command version of this command group.

Type

SlashCommandGroup

ext_variant

The prefix-based version of this command group.

Type

ext.commands.Group

subcommands

List of bridge commands in this group

Type

List[BridgeCommand]

mapped

If map_to() is used, the mapped slash command.

Type

Optional[SlashCommand]

command(*args, **kwargs)

A decorator to register a function as a subcommand.

Parameters

kwargs (Optional[Dict[str, Any]]) – Keyword arguments that are directly passed to the respective command constructors. (SlashCommand and ext.commands.Command)

@bridge.bridge_group

A decorator that is used to wrap a function as a bridge command group.

Parameters

kwargs (Optional[Dict[str, Any]]) – Keyword arguments that are directly passed to the respective command constructors. (SlashCommandGroup and ext.commands.Group)

@bridge.map_to

To be used with bridge command groups, map the main command to a slash subcommand.

Example

@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
Parameters
  • name (str) – The new name of the mapped command.

  • description (Optional[str]) – The new description of the mapped command.

Command Subclasses

class discord.ext.bridge.BridgeExtCommand(*args, **kwargs)

A subclass of ext.commands.Command that is used for bridge commands.

class discord.ext.bridge.BridgeExtGroup(*args, **kwargs)

A subclass of ext.commands.Group that is used for bridge commands.

class discord.ext.bridge.BridgeSlashCommand(*args, **kwargs)

A subclass of SlashCommand that is used for bridge commands.

class discord.ext.bridge.BridgeSlashGroup(*args, **kwargs)

A subclass of SlashCommandGroup that is used for bridge commands.

Context

BridgeContext

Attributes
Methods
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 by BridgeExtContext and BridgeApplicationContext. 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, or BridgeApplicationContext. Since they are two separate classes, it’s easy to use the BridgeContext.is_app attribute. 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}.")

New in version 2.0.

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 be reply() while in BridgeApplicationContext, this will be respond().

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 be trigger_typing() while in BridgeApplicationContext, this will be defer.

Note

There is no trigger_typing alias for this method. trigger_typing will 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 where respond() caches the message to be edited here. In BridgeApplicationContext, this will be edit.

property is_app

Whether the context is an BridgeApplicationContext or not.

Type

bool

BridgeContext Subclasses

class discord.ext.bridge.BridgeApplicationContext(*args, **kwargs)

The application context class for compatibility commands. This class is a subclass of BridgeContext and ApplicationContext. This class is meant to be used with BridgeCommand.

New in version 2.0.

Methods
class discord.ext.bridge.BridgeExtContext(*args, **kwargs)

The ext.commands context class for compatibility commands. This class is a subclass of BridgeContext and Context. This class is meant to be used with BridgeCommand.

New in version 2.0.

await delete(*, delay=None, reason=None)

This function is a coroutine.

Deletes the original response message, if it exists.

Parameters
  • delay (Optional[float]) – If provided, the number of seconds to wait before deleting the message.

  • reason (Optional[str]) – The reason for deleting the message. Shows up on the audit log.