discord_slash.model module¶
- class discord_slash.model.ChoiceData(name, value)¶
Bases:
object
Command choice data object
- Variables
name – Name of the choice, this is what the user will see
value – Values of the choice, this is what discord will return to you
- class discord_slash.model.OptionData(name, description, required=False, choices=None, options=None, **kwargs)¶
Bases:
object
Command option data object
- Variables
name – Name of the option.
description – Description of the option.
required – If the option is required.
choices – A list of
ChoiceData
, cannot be present on subcommand groupsoptions – List of
OptionData
, this will be present if it’s a subcommand group
- class discord_slash.model.CommandData(name, description=None, options=None, default_permission=True, id=None, application_id=None, version=None, **kwargs)¶
Bases:
object
Slash command data object
- Variables
name – Name of the command.
description – Description of the command.
default_permission – Indicates whether users should have permissions to run this command by default.
options – List of
OptionData
.id – Command id, this is received from discord so may not be present
application_id – The application id of the bot, required only when the application id and bot id are different. (old bots)
- class discord_slash.model.CallbackObject(func)¶
Bases:
object
Callback object of this extension.
Warning
Do not manually init this model.
- Variables
func – The coroutine of the command.
__commands_checks__ – Check of the command.
- error(coro)¶
A decorator that registers a coroutine as a local error handler.
Works the same way as it does in d.py
- Param
coroutine - The coroutine to register as the local error handler
- Raises
TypeError - The coroutine passed is not a coroutine
- async invoke(*args, **kwargs)¶
Invokes the command.
- Parameters
args – Args for the command.
- Raises
.error.CheckFailure
- is_on_cooldown(ctx) bool ¶
Checks whether the command is currently on cooldown.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
bool - indicating if the command is on cooldown.
- reset_cooldown(ctx)¶
Resets the cooldown on this command.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- get_cooldown_retry_after(ctx) float ¶
Retrieves the amount of seconds before this command can be tried again.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
float - The amount of time left on this command’s cooldown in seconds. If this is
0.0
then the command isn’t on cooldown.
- add_check(func)¶
Adds check to the command.
- Parameters
func – Any callable. Coroutines are supported.
- remove_check(func)¶
Removes check to the command.
Note
If the function is not found at the command check, it will ignore.
- Parameters
func – Any callable. Coroutines are supported.
- class discord_slash.model.CommandObject(name, cmd, _type=1)¶
Bases:
discord_slash.model.CallbackObject
Slash command object of this extension.
Warning
Do not manually init this model.
- Variables
name – Name of the command.
description – Description of the command.
allowed_guild_ids – List of the allowed guild id.
options – List of the option of the command. Used for auto_register.
connector – Kwargs connector of the command.
- add_check(func)¶
Adds check to the command.
- Parameters
func – Any callable. Coroutines are supported.
- async can_run(ctx) bool ¶
Whether the command can be run.
- Parameters
ctx (.context.SlashContext) – SlashContext for the check running.
- Returns
bool
- error(coro)¶
A decorator that registers a coroutine as a local error handler.
Works the same way as it does in d.py
- Param
coroutine - The coroutine to register as the local error handler
- Raises
TypeError - The coroutine passed is not a coroutine
- get_cooldown_retry_after(ctx) float ¶
Retrieves the amount of seconds before this command can be tried again.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
float - The amount of time left on this command’s cooldown in seconds. If this is
0.0
then the command isn’t on cooldown.
- async invoke(*args, **kwargs)¶
Invokes the command.
- Parameters
args – Args for the command.
- Raises
.error.CheckFailure
- is_on_cooldown(ctx) bool ¶
Checks whether the command is currently on cooldown.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
bool - indicating if the command is on cooldown.
- remove_check(func)¶
Removes check to the command.
Note
If the function is not found at the command check, it will ignore.
- Parameters
func – Any callable. Coroutines are supported.
- reset_cooldown(ctx)¶
Resets the cooldown on this command.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- class discord_slash.model.BaseCommandObject(name, cmd, _type=1)¶
Bases:
discord_slash.model.CommandObject
BaseCommand object of this extension.
Note
This model inherits
model.CommandObject
, so this has every variables from that.Warning
Do not manually init this model.
- Variables
has_subcommands – Indicates whether this base command has subcommands.
default_permission – Indicates whether users should have permissions to run this command by default.
permissions – Permissions to restrict use of this command.
- add_check(func)¶
Adds check to the command.
- Parameters
func – Any callable. Coroutines are supported.
- async can_run(ctx) bool ¶
Whether the command can be run.
- Parameters
ctx (.context.SlashContext) – SlashContext for the check running.
- Returns
bool
- error(coro)¶
A decorator that registers a coroutine as a local error handler.
Works the same way as it does in d.py
- Param
coroutine - The coroutine to register as the local error handler
- Raises
TypeError - The coroutine passed is not a coroutine
- get_cooldown_retry_after(ctx) float ¶
Retrieves the amount of seconds before this command can be tried again.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
float - The amount of time left on this command’s cooldown in seconds. If this is
0.0
then the command isn’t on cooldown.
- async invoke(*args, **kwargs)¶
Invokes the command.
- Parameters
args – Args for the command.
- Raises
.error.CheckFailure
- is_on_cooldown(ctx) bool ¶
Checks whether the command is currently on cooldown.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
bool - indicating if the command is on cooldown.
- remove_check(func)¶
Removes check to the command.
Note
If the function is not found at the command check, it will ignore.
- Parameters
func – Any callable. Coroutines are supported.
- reset_cooldown(ctx)¶
Resets the cooldown on this command.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- class discord_slash.model.SubcommandObject(sub, base, name, sub_group=None)¶
Bases:
discord_slash.model.CommandObject
Subcommand object of this extension.
Note
This model inherits
model.CommandObject
, so this has every variables from that.Warning
Do not manually init this model.
- Variables
base – Name of the base slash command.
subcommand_group – Name of the subcommand group.
None
if not exist.base_description – Description of the base command.
subcommand_group_description – Description of the subcommand_group.
- add_check(func)¶
Adds check to the command.
- Parameters
func – Any callable. Coroutines are supported.
- async can_run(ctx) bool ¶
Whether the command can be run.
- Parameters
ctx (.context.SlashContext) – SlashContext for the check running.
- Returns
bool
- error(coro)¶
A decorator that registers a coroutine as a local error handler.
Works the same way as it does in d.py
- Param
coroutine - The coroutine to register as the local error handler
- Raises
TypeError - The coroutine passed is not a coroutine
- get_cooldown_retry_after(ctx) float ¶
Retrieves the amount of seconds before this command can be tried again.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
float - The amount of time left on this command’s cooldown in seconds. If this is
0.0
then the command isn’t on cooldown.
- async invoke(*args, **kwargs)¶
Invokes the command.
- Parameters
args – Args for the command.
- Raises
.error.CheckFailure
- is_on_cooldown(ctx) bool ¶
Checks whether the command is currently on cooldown.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
bool - indicating if the command is on cooldown.
- remove_check(func)¶
Removes check to the command.
Note
If the function is not found at the command check, it will ignore.
- Parameters
func – Any callable. Coroutines are supported.
- reset_cooldown(ctx)¶
Resets the cooldown on this command.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- class discord_slash.model.CogBaseCommandObject(*args)¶
Bases:
discord_slash.model.BaseCommandObject
Slash command object but for Cog.
Warning
Do not manually init this model.
- add_check(func)¶
Adds check to the command.
- Parameters
func – Any callable. Coroutines are supported.
- async can_run(ctx) bool ¶
Whether the command can be run.
- Parameters
ctx (.context.SlashContext) – SlashContext for the check running.
- Returns
bool
- error(coro)¶
A decorator that registers a coroutine as a local error handler.
Works the same way as it does in d.py
- Param
coroutine - The coroutine to register as the local error handler
- Raises
TypeError - The coroutine passed is not a coroutine
- get_cooldown_retry_after(ctx) float ¶
Retrieves the amount of seconds before this command can be tried again.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
float - The amount of time left on this command’s cooldown in seconds. If this is
0.0
then the command isn’t on cooldown.
- async invoke(*args, **kwargs)¶
Invokes the command.
- Parameters
args – Args for the command.
- Raises
.error.CheckFailure
- is_on_cooldown(ctx) bool ¶
Checks whether the command is currently on cooldown.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
bool - indicating if the command is on cooldown.
- remove_check(func)¶
Removes check to the command.
Note
If the function is not found at the command check, it will ignore.
- Parameters
func – Any callable. Coroutines are supported.
- reset_cooldown(ctx)¶
Resets the cooldown on this command.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- class discord_slash.model.CogSubcommandObject(base, cmd, sub_group, name, sub)¶
Bases:
discord_slash.model.SubcommandObject
Subcommand object but for Cog.
Warning
Do not manually init this model.
- add_check(func)¶
Adds check to the command.
- Parameters
func – Any callable. Coroutines are supported.
- async can_run(ctx) bool ¶
Whether the command can be run.
- Parameters
ctx (.context.SlashContext) – SlashContext for the check running.
- Returns
bool
- error(coro)¶
A decorator that registers a coroutine as a local error handler.
Works the same way as it does in d.py
- Param
coroutine - The coroutine to register as the local error handler
- Raises
TypeError - The coroutine passed is not a coroutine
- get_cooldown_retry_after(ctx) float ¶
Retrieves the amount of seconds before this command can be tried again.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
float - The amount of time left on this command’s cooldown in seconds. If this is
0.0
then the command isn’t on cooldown.
- async invoke(*args, **kwargs)¶
Invokes the command.
- Parameters
args – Args for the command.
- Raises
.error.CheckFailure
- is_on_cooldown(ctx) bool ¶
Checks whether the command is currently on cooldown.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
bool - indicating if the command is on cooldown.
- remove_check(func)¶
Removes check to the command.
Note
If the function is not found at the command check, it will ignore.
- Parameters
func – Any callable. Coroutines are supported.
- reset_cooldown(ctx)¶
Resets the cooldown on this command.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- class discord_slash.model.ComponentCallbackObject(func, message_ids, custom_ids, component_type)¶
Bases:
discord_slash.model.CallbackObject
Internal component object. Inherits
CallbackObject
, so it has all variables from it.Warning
Do not manually init this model.
- Variables
message_ids – The message IDs registered to this callback.
custom_ids – The component custom IDs registered to this callback.
component_type – Type of the component. See :class.utils.manage_components.ComponentsType
- async invoke(ctx)¶
Invokes the component callback.
- Parameters
ctx – The
context.ComponentContext
for the interaction.
- add_check(func)¶
Adds check to the command.
- Parameters
func – Any callable. Coroutines are supported.
- async can_run(ctx) bool ¶
Whether the command can be run.
- Parameters
ctx (.context.SlashContext) – SlashContext for the check running.
- Returns
bool
- error(coro)¶
A decorator that registers a coroutine as a local error handler.
Works the same way as it does in d.py
- Param
coroutine - The coroutine to register as the local error handler
- Raises
TypeError - The coroutine passed is not a coroutine
- get_cooldown_retry_after(ctx) float ¶
Retrieves the amount of seconds before this command can be tried again.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
float - The amount of time left on this command’s cooldown in seconds. If this is
0.0
then the command isn’t on cooldown.
- is_on_cooldown(ctx) bool ¶
Checks whether the command is currently on cooldown.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
bool - indicating if the command is on cooldown.
- remove_check(func)¶
Removes check to the command.
Note
If the function is not found at the command check, it will ignore.
- Parameters
func – Any callable. Coroutines are supported.
- reset_cooldown(ctx)¶
Resets the cooldown on this command.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- class discord_slash.model.CogComponentCallbackObject(*args, **kwargs)¶
Bases:
discord_slash.model.ComponentCallbackObject
Component callback object but for Cog. Has all variables from
ComponentCallbackObject
.Warning
Do not manually init this model.
- add_check(func)¶
Adds check to the command.
- Parameters
func – Any callable. Coroutines are supported.
- async can_run(ctx) bool ¶
Whether the command can be run.
- Parameters
ctx (.context.SlashContext) – SlashContext for the check running.
- Returns
bool
- error(coro)¶
A decorator that registers a coroutine as a local error handler.
Works the same way as it does in d.py
- Param
coroutine - The coroutine to register as the local error handler
- Raises
TypeError - The coroutine passed is not a coroutine
- get_cooldown_retry_after(ctx) float ¶
Retrieves the amount of seconds before this command can be tried again.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
float - The amount of time left on this command’s cooldown in seconds. If this is
0.0
then the command isn’t on cooldown.
- async invoke(ctx)¶
Invokes the component callback.
- Parameters
ctx – The
context.ComponentContext
for the interaction.
- is_on_cooldown(ctx) bool ¶
Checks whether the command is currently on cooldown.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- Returns
bool - indicating if the command is on cooldown.
- remove_check(func)¶
Removes check to the command.
Note
If the function is not found at the command check, it will ignore.
- Parameters
func – Any callable. Coroutines are supported.
- reset_cooldown(ctx)¶
Resets the cooldown on this command.
Works the same way as it does in d.py
- Parameters
ctx (.context.SlashContext) – SlashContext
- class discord_slash.model.SlashCommandOptionType(value)¶
Bases:
enum.IntEnum
Equivalent of ApplicationCommandOptionType in the Discord API.
- SUB_COMMAND = 1¶
- SUB_COMMAND_GROUP = 2¶
- STRING = 3¶
- INTEGER = 4¶
- BOOLEAN = 5¶
- USER = 6¶
- CHANNEL = 7¶
- ROLE = 8¶
- MENTIONABLE = 9¶
- FLOAT = 10¶
- classmethod from_type(t: type)¶
Get a specific SlashCommandOptionType from a type (or object).
- Parameters
t – The type or object to get a SlashCommandOptionType for.
- Returns
model.SlashCommandOptionType
orNone
- class discord_slash.model.SlashMessage(*args, **kwargs)¶
Bases:
discord_slash.dpy_overrides.ComponentMessage
discord.py’s
discord.Message
but overriddenedit
anddelete
to work for slash command.- async edit(**fields)¶
Refer
discord.Message.edit()
.
- async delete(*, delay=None)¶
Refer
discord.Message.delete()
.
- components¶
- class discord_slash.model.PermissionData(id, type, permission, **kwargs)¶
Bases:
object
Single slash permission data.
- Variables
id – User or role id, based on following type specfic.
type – The
SlashCommandPermissionsType
type of this permission.permission – State of permission.
True
to allow,False
to disallow.
- class discord_slash.model.GuildPermissionsData(id, guild_id, permissions, **kwargs)¶
Bases:
object
Slash permissions data for a command in a guild.
- Variables
id – Command id, provided by discord.
guild_id – Guild id that the permissions are in.
permissions – List of permissions dict.
- class discord_slash.model.SlashCommandPermissionType(value)¶
Bases:
enum.IntEnum
Equivalent of ApplicationCommandPermissionType in the Discord API.
- ROLE = 1¶
- USER = 2¶
- class discord_slash.model.ComponentType(value)¶
Bases:
enum.IntEnum
An enumeration.
- actionrow = 1¶
- button = 2¶
- select = 3¶
- class discord_slash.model.ButtonStyle(value)¶
Bases:
enum.IntEnum
An enumeration.
- blue = 1¶
- blurple = 1¶
- gray = 2¶
- grey = 2¶
- green = 3¶
- red = 4¶
- URL = 5¶
- primary = 1¶
- secondary = 2¶
- success = 3¶
- danger = 4¶
- class discord_slash.model.ContextMenuType(value)¶
Bases:
enum.IntEnum
An enumeration.
- CHAT_INPUT = 1¶
- USER = 2¶
- MESSAGE = 3¶