From a51cecb00ff4c12347282671c5da482970e1d101 Mon Sep 17 00:00:00 2001 From: ElBe <90863907+ElBe-Plaq@users.noreply.github.com> Date: Wed, 14 Sep 2022 13:11:59 +0200 Subject: [PATCH] Update command_creator.py --- Bot/command_creator.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Bot/command_creator.py b/Bot/command_creator.py index 581b1fb..967dd71 100644 --- a/Bot/command_creator.py +++ b/Bot/command_creator.py @@ -2,26 +2,30 @@ Slash command creator for the discord.py The Guardians Bot. © by ElBe. -Version: 0.1.0 +Version: 0.1.3 ''' #Imports import requests +import functions #Variables -url = "https://discord.com/api/v10/applications//commands" -json = { - "name": "", - "type": 1, - "description": "" -} +url = 'https://discord.com/api/v10/applications/' + functions.json_module.get_config('Config')['Application ID'] + '/commands' headers = { - "Authorization": "Bot " + 'Authorization': 'Bot ' + functions.json_module.get_config('Config')['Token'] } -#Request -try: - r = requests.post(url, headers=headers, json=json) - print('Command /' + str(json['name']) + ' was sucessfully created.') -except Exception as e: - print('Error while trying to create the command /' + str(json['name']) + '.\n' + str(e)) +#Example Command +json = { + 'name': 'ping', + 'type': 1, + 'description': 'Shows you the ping of the bot.' +} + +#Function +def create_command(json): + try: + r = requests.post(url, headers=headers, json=json) + print('Command /' + str(json['name']) + ' was sucessfully created.') + except Exception as e: + print('Error while trying to create the command /' + str(json['name']) + '.\n' + str(e))