discord-interactions

discord_slash.cog_ext module

discord_slash.cog_ext.cog_slash(*, name: Optional[str] = None, description: Optional[str] = None, guild_ids: Optional[List[int]] = None, options: Optional[List[dict]] = None, default_permission: bool = True, permissions: Optional[Dict[int, list]] = None, connector: Optional[dict] = None)

Decorator for Cog to add slash command.

Almost same as client.SlashCommand.slash().

Example:

class ExampleCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @cog_ext.cog_slash(name="ping")
    async def ping(self, ctx: SlashContext):
        await ctx.send(content="Pong!")
Parameters
  • name (str) – Name of the slash command. Default name of the coroutine.

  • description (str) – Description of the slash command. Default None.

  • guild_ids (List[int]) – List of Guild ID of where the command will be used. Default None, which will be global command.

  • options (List[dict]) – Options of the slash command. This will affect auto_convert and command data at Discord API. Default None.

  • default_permission (bool) – Sets if users have permission to run slash command by default, when no permissions are set. Default True.

  • permissions (dict) – Dictionary of permissions of the slash command. Key being target guild_id and value being a list of permissions to apply. Default None.

  • connector (dict) – Kwargs connector for the command. Default None.

discord_slash.cog_ext.cog_subcommand(*, base, subcommand_group=None, name=None, description: Optional[str] = None, base_description: Optional[str] = None, base_desc: Optional[str] = None, base_default_permission: bool = True, base_permissions: Optional[Dict[int, list]] = None, subcommand_group_description: Optional[str] = None, sub_group_desc: Optional[str] = None, guild_ids: Optional[List[int]] = None, options: Optional[List[dict]] = None, connector: Optional[dict] = None)

Decorator for Cog to add subcommand.

Almost same as client.SlashCommand.subcommand().

Example:

class ExampleCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @cog_ext.cog_subcommand(base="group", name="say")
    async def group_say(self, ctx: SlashContext, text: str):
        await ctx.send(content=text)
Parameters
  • base (str) – Name of the base command.

  • subcommand_group (str) – Name of the subcommand group, if any. Default None which represents there is no sub group.

  • name (str) – Name of the subcommand. Default name of the coroutine.

  • description (str) – Description of the subcommand. Default None.

  • base_description (str) – Description of the base command. Default None.

  • base_desc – Alias of base_description.

  • base_default_permission (bool) – Sets if users have permission to run slash command by default, when no permissions are set. Default True.

  • base_permissions (dict) – Dictionary of permissions of the slash command. Key being target guild_id and value being a list of permissions to apply. Default None.

  • subcommand_group_description (str) – Description of the subcommand_group. Default None.

  • sub_group_desc – Alias of subcommand_group_description.

  • guild_ids (List[int]) – List of guild ID of where the command will be used. Default None, which will be global command.

  • options (List[dict]) – Options of the subcommand. This will affect auto_convert and command data at Discord API. Default None.

  • connector (dict) – Kwargs connector for the command. Default None.

discord_slash.cog_ext.cog_context_menu(*, name: str, guild_ids: Optional[list] = None, target: int = 1)

Decorator that adds context menu commands.

Parameters
  • target (int) – The type of menu.

  • name (str) – A name to register as the command in the menu.

  • guild_ids (list) – A list of guild IDs to register the command under. Defaults to None.

discord_slash.cog_ext.permission(guild_id: int, permissions: list)

Decorator that add permissions. This will set the permissions for a single guild, you can use it more than once for each command.

Parameters
  • guild_id (int) – ID of the guild for the permissions.

  • permissions (list) – List of permissions to be set for the specified guild.

discord_slash.cog_ext.cog_component(*, messages: Optional[Union[int, discord.message.Message, list]] = None, components: Optional[Union[str, dict, list]] = None, use_callback_name=True, component_type: Optional[int] = None)

Decorator for component callbacks in cogs.

Almost same as client.SlashCommand.component_callback().

Parameters
  • messages (Union[discord.Message, int, list]) – If specified, only interactions from the message given will be accepted. Can be a message object to check for, or the message ID or list of previous two. Empty list will mean that no interactions are accepted.

  • components (Union[str, dict, list]) – If specified, only interactions with custom_id of given components will be accepted. Defaults to the name of callback if use_callback_name=True. Can be a custom ID (str) or component dict (actionrow or button) or list of previous two.

  • use_callback_name (bool) – Whether the custom_id defaults to the name of callback if unspecified. If False, either messages or components must be specified.

  • component_type (Optional[int]) – The type of the component to avoid collisions with other component types. See model.ComponentType.

Raises

.error.DuplicateCustomID, .error.IncorrectFormat