-
Notifications
You must be signed in to change notification settings - Fork 4
API Reference
-
@
discord.ext.slash.cmd(**kwargs)
Decorator that transforms a coroutine into aCommand, passing throughkwargs. -
@
discord.ext.slash.group(**kwargs)
Decorator that transforms a coroutine into aGroup, passing throughkwargs.
class discord.ext.slash.SlashBot(debug_guild=None, **kwargs)
A bot that supports slash commands.
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 toNoneor do not set it at all.
-
app_info(Optional[AppInfo])
Cached output ofapplication_info(). Might not even be present untilon_readyhas fired at least once.
- @
slash_cmd(**kwargs)
A shortcut decorator (called with parentheses) that creates aCommand, passing thekwargsthrough, and adds it to the command set viaslash.add().
- @
slash_group(**kwargs)
A shortcut decorator (called with parentheses) that creates aGroup, passing thekwargsthrough, and adds it to the command set viaslash.add().
-
add_slash_group(func,**kwargs)
Non-decorator form ofslash_group-
func(coroutine) — the coroutine
-
-
add_slash_cog(cog)
Adds all attributes ofcogthat are instances ofCommandorGroup.-
cog(Any) — the object/class/anything containing commands and groups
-
class discord.ext.slash.Command(coro, **kwargs)
A slash command.
See attributes for most of them
-
check(coroutine)
A coroutine to run before calling the command. If it returnsFalse(not falsy,False) then the command is not run.
-
coro(coroutine)
Required — The coroutine that is executed when the command is called.
-
name(str)
The name of the command.
-
qualname(str)
The fully qualified name of the command, including names of parent groups.
-
description(str)
The description of the command, shown to users under the name.
-
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(Optional[int])
If specified, the command is a guild command for this guild. Otherwise, it is a global command.
-
parent(Optional[Group])
The (sub)command group that contains this command.
- @
check
A decorator that sets the coroutine as the check for the command.
class discord.ext.slash.Group(coro, **kwargs)
A group of slash commands.
See attributes
Same as Command, with the following differences:
-
coro(coroutine)
Required — The coroutine that is run before any subcommands or commands in subgroups are called. If this returnsFalse(not falsy,False)
Same decorators and add_* methods as SlashBot minus add_slash_cog
class discord.ext.slash.Option(description, type=STRING, **kwargs)
An option passed to a Command
-
description(str)
Required — The description of the option, displayed to users.
-
type(ApplicationCommandOptionType)
The data type of the option. This defaults toApplicationCommandOptionType.STRING.
-
name(str)
The name of the option, if it needs to be different from the function argument name.
-
default(bool)
IfTrue, this is the first option suggested to users to fill in. Only one option can bedefault. This defaults toFalse.
-
required(bool)
IfTrue, failing to specify this option will result in the command not being invoked by Discord. This defaults toFalse.
-
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 throughChoice.from_data().
Same as constructor arguments.
None
class discord.ext.slash.Choice(name, value)
A single choice for an option's value.
-
name(str)
The value of the choice that is displayed to the user.
-
value(str)
The value of the choice that is displayed to the application.
Same as constructor arguments.
-
classmethodfrom_data(data)
Create a Choice from more arbitrary data. Astrvalue will be doubled intonameandvalue; a mapping will be**ed into the constructor; a Choice will be passed through.
class discord.ext.slash.Context/Interaction
The context surrounding an interaction. Not meant to be manually instantiated
-
id(int)
The interaction ID.
-
guild(Union[discord.Guild,discord.Object])
The guild where the interaction took place. Can be an Object with only theidattribute available if the client is not in the guild.
-
channel(Union[discord.TextChannel,discord.Object])
The channel where the command was run. Same deal with Object.
-
author(discord.Member)
The member who ran the command. Ifguildis 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)
The command that was run.
-
options(Mapping[str, Union[str,int,bool,discord.Member,discord.TextChannel,discord.Role,discord.Object]])
Mapping of names to values of options that actually will be passed/have been passed to the command.
-
me(Optional[discord.Member])
The client, as aMemberin this context. Can beNoneif the client is not in the guild.
-
client(SlashBot)
The bot.
-
webhook(discord.Webhook)
Webhook used for sending followup messages.Noneuntil the interaction response itself has been sent. Valid for 15 minutes.
-
await
respond(content='',*,embeds=None,allowed_mentions=None, rtype=InteractionResponseType.ChannelMessageWithSource)
Respond to the interaction. If called again, edits the response. Parameters have the same meaning asdiscord.Webhook.sendbesides: -
rtype— the type of response to send (only considered for sending, not editing) (seeInteractionResponseType)
-
await
delete()
Delete the original interaction response message.
-
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 todiscord.TextChannel.send.
Possible types for Command Options to be.
1. Marks a sub-Command. Included only for completion - using this in normal code would cause problems.
2. Marks a Group. Same note as above.
3. Options of this type are passed as str.
4. Options of this type are passed as int.
5. Options of this type are passed as bool.
6. Options of this type are passed as discord.Member or discord.Object.
7. Options of this type are passed as discord.TextChannel or discord.Object.
8. Options of this type are passed as discord.Role or discord.Object.
Possible ways to respond to an interaction.
1. Only used to ACK a Ping, which only happens on a webhook. This library uses the gateway. Included only for completeness.
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.
3. Respond with a message, but don't show user input. Probably best for admin commands.
4. Respond with a message, and show user input. Default.
5. Show user input, but do nothing else. Best for regular commands that require no response.