Deleting Commands¶
Deleting commands is similar to Editing Commands except the new_command
parameter is not available.
Simply pass the command id instead. Pair this with getting commands and you should be good to go in finding what specific commands to delete.
from dispike import Dispike
bot = Dispike(...)
bot.delete_command(
command_id=12345
)
API Reference¶
¶
Deletes a command, provided with a command_id
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command_id |
Union[int, dispike.incoming.incoming_interactions.IncomingApplicationCommand] |
Command ID required |
required |
guild_only |
bool |
Whether to be a global action or target a guild. Defaults to False. |
False |
guild_id_passed |
[type] |
Guild ID if guild_only is set to True. Defaults to None. |
None |
Returns:
Type | Description |
---|---|
bool |
bool: True if status code is 201, otherwise an error will be raised. |
Exceptions:
Type | Description |
---|---|
TypeError |
Invalid types passed. |
DiscordAPIError |
any Discord returned errors. |
Source code in dispike/main.py
@logger.catch(reraise=True, message="Issue with deleting commands from Discord")
def delete_command(
self, command_id: typing.Union[int, IncomingApplicationCommand], guild_only=False, guild_id_passed=None
) -> bool:
"""Deletes a command, provided with a command_id
Args:
command_id (typing.Union[int, IncomingApplicationCommand]): Command ID required
guild_only (bool, optional): Whether to be a global action or target a guild. Defaults to False.
guild_id_passed ([type], optional): Guild ID if guild_only is set to True. Defaults to None.
Returns:
bool: True if status code is 201, otherwise an error will be raised.
Raises:
TypeError: Invalid types passed.
DiscordAPIError: any Discord returned errors.
"""
if isinstance(command_id, IncomingApplicationCommand):
command_id = command_id.id
elif isinstance(command_id, (str, int)):
command_id = int(command_id)
else:
raise TypeError("The command ID must be either an interger or an IncomingApplicationCommand object.")
if guild_only:
if not guild_id_passed:
raise TypeError(
"You cannot have guild_only == True and NOT pass any guild id."
)
_url = f"/guilds/{guild_id_passed}/commands/{command_id}"
else:
_url = f"/commands/{command_id}"
try:
_send_request = self._registrator._client.delete(
_url, headers=self._registrator.request_headers
)
if _send_request.status_code != 204:
raise DiscordAPIError(_send_request.status_code, _send_request.text)
return True
except DiscordAPIError:
logger.exception("Discord API Failure.")
raise