discord_slash.utils.manage_commands module¶
- async discord_slash.utils.manage_commands.add_slash_command(bot_id, bot_token: str, guild_id, cmd_name: str, description: str, options: Optional[list] = None)¶
A coroutine that sends a slash command add request to Discord API.
- Parameters
bot_id – User ID of the bot.
bot_token – Token of the bot.
guild_id – ID of the guild to add command. Pass None to add global command.
cmd_name – Name of the command. Must match the regular expression
^[a-z0-9_-]{1,32}$
.description – Description of the command.
options – List of the function.
- Returns
JSON Response of the request.
- Raises
error.RequestFailure
- Requesting to Discord API has failed.
- async discord_slash.utils.manage_commands.remove_slash_command(bot_id, bot_token, guild_id, cmd_id)¶
A coroutine that sends a slash command remove request to Discord API.
- Parameters
bot_id – User ID of the bot.
bot_token – Token of the bot.
guild_id – ID of the guild to remove command. Pass None to remove global command.
cmd_id – ID of the command.
- Returns
Response code of the request.
- Raises
error.RequestFailure
- Requesting to Discord API has failed.
- async discord_slash.utils.manage_commands.get_all_commands(bot_id, bot_token, guild_id=None)¶
A coroutine that sends a slash command get request to Discord API.
- Parameters
bot_id – User ID of the bot.
bot_token – Token of the bot.
guild_id – ID of the guild to get commands. Pass None to get all global commands.
- Returns
JSON Response of the request.
- Raises
error.RequestFailure
- Requesting to Discord API has failed.
- async discord_slash.utils.manage_commands.remove_all_commands(bot_id, bot_token, guild_ids: Optional[List[int]] = None)¶
Remove all slash commands.
- Parameters
bot_id – User ID of the bot.
bot_token – Token of the bot.
guild_ids – List of the guild ID to remove commands. Pass
None
to remove only the global commands.
- async discord_slash.utils.manage_commands.remove_all_commands_in(bot_id, bot_token, guild_id=None)¶
Remove all slash commands in area.
- Parameters
bot_id – User ID of the bot.
bot_token – Token of the bot.
guild_id – ID of the guild to remove commands. Pass None to remove all global commands.
- async discord_slash.utils.manage_commands.get_all_guild_commands_permissions(bot_id, bot_token, guild_id)¶
A coroutine that sends a gets all the commands permissions for that guild.
- Parameters
bot_id – User ID of the bot.
bot_token – Token of the bot.
guild_id – ID of the guild to get permissions.
- Returns
JSON Response of the request. A list of <https://discord.com/developers/docs/interactions/application-commands#get-application-command-permissions>.
- Raises
error.RequestFailure
- Requesting to Discord API has failed.
- async discord_slash.utils.manage_commands.get_guild_command_permissions(bot_id, bot_token, guild_id, command_id)¶
A coroutine that sends a request to get a single command’s permissions in guild
- Parameters
bot_id – User ID of the bot.
bot_token – Token of the bot.
guild_id – ID of the guild to update permissions on.
command_id – ID for the command to update permissions on.
- Returns
JSON Response of the request. A list of <https://discord.com/developers/docs/interactions/application-commands#edit-application-command-permissions>
- Raises
error.RequestFailure
- Requesting to Discord API has failed.
- async discord_slash.utils.manage_commands.update_single_command_permissions(bot_id, bot_token, guild_id, command_id, permissions)¶
A coroutine that sends a request to update a single command’s permissions in guild
- Parameters
bot_id – User ID of the bot.
bot_token – Token of the bot.
guild_id – ID of the guild to update permissions on.
command_id – ID for the command to update permissions on.
permissions – List of permissions for the command.
- Returns
JSON Response of the request. A list of <https://discord.com/developers/docs/interactions/application-commands#edit-application-command-permissions>
- Raises
error.RequestFailure
- Requesting to Discord API has failed.
- async discord_slash.utils.manage_commands.update_guild_commands_permissions(bot_id, bot_token, guild_id, cmd_permissions)¶
A coroutine that updates permissions for all commands in a guild.
- Parameters
bot_id – User ID of the bot.
bot_token – Token of the bot.
guild_id – ID of the guild to update permissions.
cmd_permissions – List of dict with permissions for each commands.
- Returns
JSON Response of the request. A list of <https://discord.com/developers/docs/interactions/application-commands#batch-edit-application-command-permissions>.
- Raises
error.RequestFailure
- Requesting to Discord API has failed.
- discord_slash.utils.manage_commands.create_option(name: str, description: str, option_type: Union[int, type], required: bool, choices: Optional[list] = None) dict ¶
Creates option used for creating slash command.
- Parameters
name – Name of the option.
description – Description of the option.
option_type – Type of the option.
required – Whether this option is required.
choices – Choices of the option. Can be empty.
- Returns
dict
Note
An option with
required=False
will not pass anything to the command function if the user doesn’t pass that option when invoking the command. You must set the the relevant argument’s function to a default argument, egargname = None
.Note
choices
must either be a list of option type dicts or a list of single string values.
- discord_slash.utils.manage_commands.generate_options(function: collections.abc.Callable, description: str = 'No description.', connector: Optional[dict] = None) list ¶
Generates a list of options from the type hints of a command. You currently can type hint: str, int, bool, discord.User, discord.Channel, discord.Role
Warning
This is automatically used if you do not pass any options directly. It is not recommended to use this.
- Parameters
function – The function callable of the command.
description – The default argument description.
connector – Kwargs connector of the command.
- discord_slash.utils.manage_commands.create_choice(value: Union[str, int], name: str)¶
Creates choices used for creating command option.
- Parameters
value – Value of the choice.
name – Name of the choice.
- Returns
dict
- discord_slash.utils.manage_commands.create_permission(id: int, id_type: Union[int, discord_slash.model.SlashCommandPermissionType], permission: bool)¶
Create a single command permission.
- Parameters
id – Target id to apply the permission on.
id_type – Type of the id,
model.SlashCommandPermissionsType
.permission – State of the permission.
True
to allow access,False
to disallow access.
- Returns
dict
Note
For @everyone permission, set id_type as role and id as guild id.
- discord_slash.utils.manage_commands.create_multi_ids_permission(ids: List[int], id_type: Union[int, discord_slash.model.SlashCommandPermissionType], permission: bool)¶
Creates a list of permissions from list of ids with common id_type and permission state.
- Parameters
ids – List of target ids to apply the permission on.
id_type – Type of the id.
permission – State of the permission.
True
to allow access,False
to disallow access.
- discord_slash.utils.manage_commands.generate_permissions(allowed_roles: Optional[List[int]] = None, allowed_users: Optional[List[int]] = None, disallowed_roles: Optional[List[int]] = None, disallowed_users: Optional[List[int]] = None)¶
Creates a list of permissions.
- Parameters
allowed_roles – List of role ids that can access command.
allowed_users – List of user ids that can access command.
disallowed_roles – List of role ids that should not access command.
disallowed_users – List of users ids that should not access command.
- Returns
list