Created
September 29, 2022 09:11
-
-
Save ccall48/e4132cd3b77fd199618ed7320e03eafb to your computer and use it in GitHub Desktop.
delete discord application commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import time | |
class AppCommands: | |
""" | |
Get Guild Application Commands | |
GET/applications/{application.id}/guilds/{guild.id}/commands | |
Delete Guild Application Command | |
DELETE/applications/{application.id}/guilds/{guild.id}/commands/{command.id} | |
Delete a guild command. Returns 204 No Content on success. | |
""" | |
API_BASE = 'https://discord.com/api/v10' | |
def __init__(self, application_id: int, guild_id: int, bot_token: str, api_base=API_BASE): | |
self.api_base = api_base | |
self.app_id = application_id | |
self.guild_id = guild_id | |
self.bot_token = bot_token | |
self.headers = {"authorization": f"Bot {self.bot_token}"} | |
def get_guild_app_commands(self): | |
resp = requests.get( | |
f'{self.api_base}/applications/{self.app_id}/guilds/{self.guild_id}/commands', | |
headers=self.headers | |
) | |
return [x['id'] for x in resp.json()] | |
def delete_guild_app_commands(self): | |
commands = self.get_guild_app_commands() | |
if not commands: | |
return f'No commands found\nApplication.id: {self.app_id}\nGuild.id: {self.guild_id}' | |
for comm_id in commands: | |
resp = requests.delete( | |
f'{self.api_base}/applications/{self.app_id}/guilds/{self.guild_id}/commands/{comm_id}', | |
headers=self.headers | |
) | |
print(f'{resp} command {comm_id} deleted') | |
time.sleep(5) | |
if __name__ == '__main__': | |
guild = AppCommands( | |
application_id = APP_SNOWFLAKE_ID, | |
guild_id = GUILD_SNOWFLAKE_ID, | |
bot_token = 'YOUR_BOT_TOKEN' | |
) | |
# # use this to see what app commands are connected to app id for guild | |
#print(guild.get_guild_app_commands()) | |
# # use this to collect app command ids and delete them from guild. | |
#print(guild.delete_guild_app_commands()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment