Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

API Reference

Kenny2github edited this page Feb 1, 2021 · 7 revisions

Functions

  • @discord.ext.slash.cmd(**kwargs)
    Decorator that transforms a coroutine into a Command, passing through kwargs.
  • @discord.ext.slash.group(**kwargs)
    Decorator that transforms a coroutine into a Group, passing through kwargs.

Classes

SlashBot

class discord.ext.slash.SlashBot(debug_guild=None, **kwargs)
       A bot that supports slash commands.

Constructor Arguments

All arguments passed to discord.ext.commands.Bot are valid as well.

  • debug_guild — While testing your bot, it may be useful to have instant command updates for global commands. Setting this to a guild ID will redirect all global commands to commands specific to that guild. Once in production, set this to None or do not set it at all.

Attributes

app_info

slash

  • slash (set)
    All top-level Commands and Groups currently registered in code.

Methods

slash_cmd

  • @slash_cmd(**kwargs)
    A shortcut decorator (called with parentheses) that creates a Command, passing the kwargs through, and adds it to the command set via slash.add().

add_slash

  • add_slash(func, **kwargs)
    Non-decorator form of slash_cmd.

slash_group

  • @slash_group(**kwargs)
    A shortcut decorator (called with parentheses) that creates a Group, passing the kwargs through, and adds it to the command set via slash.add().

add_slash_group

  • add_slash_group(func, **kwargs)
    Non-decorator form of slash_group

add_slash_cog

  • add_slash_cog(cog)
    Adds all attributes of cog that are instances of Command or Group.
    • cog (Any) — the object/class/anything containing commands and groups

Command

class discord.ext.slash.Command(coro, **kwargs)
       A slash command.

Constructor Arguments

See attributes for most of them

check

  • check (coroutine)
    A coroutine to run before calling the command. If it returns False (not falsy, False) then the command is not run.

Attributes

coro

  • coro (coroutine)
    Required — The coroutine that is executed when the command is called.

name

  • name (str)
    The name of the command.

qualname

  • qualname (str)
    The fully qualified name of the command, including names of parent groups.

description

  • description (str)
    The description of the command, shown to users under the name.

id

  • id (Optional[int])
    The unique command ID. Can be None when the command is not yet synced with Discord, or when the command is not a top-level command.

guild_id

  • guild_id (Optional[int])
    If specified, the command is a guild command for this guild. Otherwise, it is a global command.

options

  • options (Mapping[str, Option])
    Options that the command takes. (Not passable as a parameter.)

parent

  • parent (Optional[Group])
    The (sub)command group that contains this command.

Methods

check

  • @check
    A decorator that sets the coroutine as the check for the command.

Group

class discord.ext.slash.Group(coro, **kwargs)
       A group of slash commands.

Constructor Arguments

See attributes

Attributes

Same as Command, with the following differences:

coro

slash

  • slash (Mapping[str, Union[Group, Command]])
    Mapping of name to subcommand/group.

Methods

Same decorators and add_* methods as SlashBot minus add_slash_cog

Option

class discord.ext.slash.Option(description, type=STRING, **kwargs)
       An option passed to a Command

Constructor Arguments

description

  • description (str)
    Required — The description of the option, displayed to users.

type

name

  • name (str)
    The name of the option, if it needs to be different from the function argument name.

default

  • default (bool)
    No idea what this does. It doesn't work anyway. This library will receive an update when this option becomes functional.

required

  • required (bool)
    If True, failing to specify this option will result in the command not being invoked by Discord. This defaults to False.

choices

  • choices (Optional[Iterable[Union[str, Mapping[str, str], Choice]]])
    If specified, only these choices are allowed for this option. Items of the iterable are passed through Choice.from_data().

Attributes

Same as constructor arguments.

Methods

None

Choice

class discord.ext.slash.Choice(name, value)
       A single choice for an option's value.

Constructor Arguments

name

  • name (str)
    The value of the choice that is displayed to the user.

value

  • value (str)
    The value of the choice that is displayed to the application.

Attributes

Same as constructor arguments.

Methods

from_data

  • classmethod from_data(data)
    Create a Choice from more arbitrary data. A str value will be doubled into name and value; a mapping will be **ed into the constructor; a Choice will be passed through.
    • data (Union[str, Mapping[str, str], Choice]) — the data to convert from

Context

class discord.ext.slash.Context/Interaction
       The context surrounding an interaction. Not meant to be manually instantiated

Attributes

id

  • id (int)
    The interaction ID.

guild

  • guild (Union[discord.Guild, discord.Object])
    The guild where the interaction took place. Can be an Object with only the id attribute available if the client is not in the guild.

channel

author

  • author (discord.Member)
    The member who ran the command. If guild is an Object, this will be a partial Member object for which many methods that require the guild will break, and should not be relied upon.

command

  • command (Command)
    The command that was run.

options

me

  • me (Optional[discord.Member])
    The client, as a Member in this context. Can be None if the client is not in the guild.

client

webhook

  • webhook (discord.Webhook)
    Webhook used for sending followup messages. None until the interaction response itself has been sent. Valid for 15 minutes.

Methods

respond

delete

  • await delete()
    Delete the original interaction response message.

send

  • await send(*args, **kwargs)
    Send a message in the channel where the command was run. This is the only method that works after the interaction token has expired (15 minutes), but it only works if the client is present in the server as a bot user. Parameters are forwarded to discord.TextChannel.send.

Enumerations

ApplicationCommandOptionType

Possible types for Command Options to be.

SUB_COMMAND

1. Marks a sub-Command. Included only for completion - using this in normal code would cause problems.

SUB_COMMAND_GROUP

2. Marks a Group. Same note as above.

STRING

3. Options of this type are passed as str.

INTEGER

4. Options of this type are passed as int.

BOOLEAN

5. Options of this type are passed as bool.

USER

6. Options of this type are passed as discord.Member or discord.Object.

CHANNEL

7. Options of this type are passed as discord.TextChannel or discord.Object.

ROLE

8. Options of this type are passed as discord.Role or discord.Object.

InteractionResponseType

Possible ways to respond to an interaction.

Pong

1. Only used to ACK a Ping, which only happens on a webhook. This library uses the gateway. Included only for completeness.

Acknowledge

2. ACK an interaction without sending a message and without showing user input. Probably best for debugging commands, or commands that only have server-side effects.

ChannelMessage

3. Respond with a message, but don't show user input. Probably best for admin commands.

ChannelMessageWithSource

4. Respond with a message, and show user input. Default.

AcknowledgeWithSource

5. Show user input, but do nothing else. Best for regular commands that require no response.

MessageFlags

Discord message flags.

CROSSPOSTED

1 << 0

this message has been published to subscribed channels (via Channel Following)

IS_CROSSPOST

1 << 1

this message originated from a message in another channel (via Channel Following

SUPPRESS_EMBEDS

1 << 2

do not include any embeds when serializing this message

SOURCE_MESSAGE_DELETED

1 << 3

the source message for this crosspost has been deleted (via Channel Following)

URGENT

1 << 4

this message came from the urgent message system

HAS_THREAD

1 << 5. Name provided by @advaith#9121 (190916650143318016) in the Discord Developers server. Functionality not released yet.

EPHEMERAL

1 << 6. This message is only visible to the command-invoking user, and is dismissible by them.

Clone this wiki locally