discord_slash.http module¶
- class discord_slash.http.CustomRoute(method, path, **parameters)¶
Bases:
discord.http.Route
discord.py’s Route but changed
BASE
to use at slash command.- BASE = 'https://discord.com/api/v8'¶
- class discord_slash.http.SlashCommandRequest(logger, _discord, application_id)¶
Bases:
object
- property application_id¶
- put_slash_commands(slash_commands: list, guild_id)¶
Sends a slash command put request to the Discord API
slash_commands
must contain all the commands- Parameters
slash_commands – List of all the slash commands to make a put request to discord with.
guild_id – ID of the guild to set the commands on. Pass None for the global scope.
- remove_slash_command(guild_id, cmd_id)¶
Sends a slash command delete request to Discord API.
- Parameters
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.
- get_all_commands(guild_id=None)¶
Sends a slash command get request to Discord API for all commands.
- Parameters
guild_id – ID of the guild to get commands. Pass None to get global commands.
- Returns
JSON Response of the request.
- get_all_guild_commands_permissions(guild_id)¶
Sends a slash command get request to Discord API for all permissions of a guild.
- Parameters
guild_id – ID of the target guild to get registered command permissions of.
- Returns
JSON Response of the request.
- update_guild_commands_permissions(guild_id, perms_dict)¶
Sends a slash command put request to the Discord API for setting all command permissions of a guild.
- Parameters
guild_id – ID of the target guild to register command permissions.
- Returns
JSON Response of the request.
- add_slash_command(guild_id, cmd_name: str, description: str, options: Optional[list] = None, context: Optional[dict] = None)¶
Sends a slash command add request to Discord API.
- Parameters
guild_id – ID of the guild to add command. Pass None to add global command.
cmd_name – Name of the command. Must be match the regular expression
^[a-z0-9_-]{1,32}$
.description – Description of the command.
options – List of the function.
context – Dictionary of context. Sends as separate.
- Returns
JSON Response of the request.
- command_request(method, guild_id, url_ending='', **kwargs)¶
Sends a command request to discord (post, get, delete, etc)
- Parameters
method – HTTP method.
guild_id – ID of the guild to make the request on. None to make a request on the global scope.
url_ending – String to append onto the end of the url.
**kwargs – Kwargs to pass into discord.py’s request function
- post_followup(_resp, token, files: Optional[List[discord.file.File]] = None)¶
Sends command followup response POST request to Discord API.
- Parameters
_resp (dict) – Command response.
token – Command message token.
files (List[discord.File]) – Files to send. Default
None
- Returns
Coroutine
- post_initial_response(_resp, interaction_id, token)¶
Sends an initial “POST” response to the Discord API.
- Parameters
_resp (dict) – Command response.
interaction_id – Interaction ID.
token – Command message token.
- Returns
Coroutine
- command_response(token, use_webhook, method, interaction_id=None, url_ending='', **kwargs)¶
Sends a command response to discord (POST, PATCH, DELETE)
- Parameters
token – Interaction token
use_webhook – Whether to use webhooks
method – The HTTP request to use
interaction_id – The id of the interaction
url_ending – String to append onto the end of the url.
**kwargs –
Kwargs to pass into discord.py’s request function
- Returns
Coroutine
- edit(_resp, token, message_id='@original', files: Optional[List[discord.file.File]] = None)¶
Sends edit command response PATCH request to Discord API.
- Parameters
_resp (dict) – Edited response.
token – Command message token.
message_id – Message ID to edit. Default initial message.
files (List[discord.File]) – Files. Default
None
- Returns
Coroutine
- delete(token, message_id='@original')¶
Sends delete command response POST request to Discord API.
- Parameters
token – Command message token.
message_id – Message ID to delete. Default initial message.
- Returns
Coroutine