├── .deepsource.toml ├── LICENSE ├── README.md └── discord-slash-commands.py /.deepsource.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[analyzers]] 4 | name = "python" 5 | enabled = true 6 | 7 | [analyzers.meta] 8 | runtime_version = "3.x.x" 9 | 10 | [[transformers]] 11 | name = "autopep8" 12 | enabled = true 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 iSaluki 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Slash Command Tools 2 | 3 | [![Discord](https://img.shields.io/discord/697477880938102925?style=for-the-badge)](https://discord.gg/vzehFuy9rU) 4 | 5 | 6 | [![DeepSource](https://deepsource.io/gh/iSaluki/discord-slash-commands.svg/?label=active+issues&show_trend=true)](https://deepsource.io/gh/iSaluki/discord-slash-commands/?ref=repository-badge) 7 | 8 | 9 | A Python-based tool to allow you to easily create, list and delete Discord slash commands. 10 | You just need to enter a few details and then the script will handle the rest for you. 11 | Supports global and guild commands. 12 | 13 | 14 | # Dependencies 15 | 16 | Requires the `requests` module to be installed. 17 | 18 | Install this through a command line with `pip install requests` 19 | 20 | # How to use 21 | 22 | **Note:** This is a very basic set of instructions, and may be slightly out of date as this tool is in active development and is constantly changing. Once it's nearer completion, we'll have a more stable tutorial available. 23 | 24 | 1) Download and run the [Python script](https://github.com/iSaluki/discord-slash-commands/blob/main/discord-slash-commands.py) 25 | 2) Make sure you've added the `applications.commands` scope to your bot for the server you want to add the command to (if you're doing guild based). Replace BOT_ID with your bot's client ID in this link: https://discord.com/api/oauth2/authorize?client_id=BOT_ID&scope=applications.commands 26 | 2) Enter all the details into the CLI, you will be prompted for them one by one. 27 | 3) Head over to Discord and see the new slash commands 28 | 29 | Want to run the code in your browser? [Do it here!](https://repl.it/@saluki/discord-slash-commands) 30 | 31 | # Features 32 | 33 | Main features available now. 34 | 35 | `CREATE` a new slash command for a bot, in a specific guild or globally. You can also update these by overriding them. 36 | 37 | `GET` commands for a bot, either globally or in a specific guild. 38 | 39 | `DELETE` commands for a bot, either globally or in a specific guild. 40 | 41 | 42 | # Notes 43 | 44 | This script was written in a short period of time and can not do everything, and may also have bugs. 45 | Please feel free to contribute to it, or to open issues with any problems you're having. 46 | 47 | This is currently a very basic script, but I plan to add more to it in future. It is not intended for use directly in a bot, but more for testing, and for setting up commands for testing or getting some global commands working. 48 | 49 | 50 | Enjoy! 51 | 52 | # Coming soon 53 | 54 | - Python module, allowing devs to install via pip, import into scripts and use in more technical applications. 55 | -------------------------------------------------------------------------------- /discord-slash-commands.py: -------------------------------------------------------------------------------- 1 | # This script is completely free to use for any purpose, under the MIT license. If you have any problems or suggestions, please open an issue on GitHub. 2 | 3 | 4 | import requests 5 | 6 | 7 | def CreateCommand(): 8 | application_id = input("Enter application ID: ") 9 | while not application_id.isdigit(): 10 | application_id = input("Enter application ID: ") 11 | token = input("Enter bot token: ") 12 | cmdType = input("[Gl]obal or [G]uild?: ").lower() 13 | if cmdType == "global" or "gl": 14 | url = "https://discord.com/api/v8/applications/"+application_id+"/commands" 15 | elif cmdType == "guild" or "gu": 16 | guild_id = input("Enter guild ID: ") 17 | while not guild_id.isdigit(): 18 | guild_id = input("Enter guild ID: ") 19 | url = "https://discord.com/api/v8/applications/" + \ 20 | application_id+"/guilds/"+guild_id+"/commands" 21 | else: 22 | print("Please choose a valid option.") 23 | 24 | cmd_name = input("Enter command name: ") 25 | cmd_description = input("Enter command description: ") 26 | value_name = input("Value name: ") 27 | value_description = input("Value description: ") 28 | #cmd_Type = input("Enter command type (integer): ") 29 | cmd_isRequired = input("Is the command required? (True/False): ") 30 | cmd_isRequired = bool(cmd_isRequired) 31 | # while not cmd_Type.isdigit(): 32 | # cmd_Type = input("Enter command type (integer): ") 33 | #cmd_Type = int(cmd_Type) 34 | 35 | print("Starting choices editor...") 36 | 37 | json = { 38 | "name": cmd_name, 39 | "description": cmd_description, 40 | "options": [ 41 | { 42 | "name": value_name, 43 | "description": value_description, 44 | "type": 3, 45 | "required": cmd_isRequired, 46 | 47 | }, 48 | ] 49 | } 50 | 51 | headers = { 52 | "Authorization": "Bot " + token 53 | } 54 | 55 | print(json) 56 | print(headers) 57 | 58 | r = requests.post(url, headers=headers, json=json) 59 | print(r.content) 60 | funcSelector() 61 | 62 | 63 | def DeleteCommand(): 64 | application_id = input("Enter application ID: ") 65 | while not application_id.isdigit(): 66 | application_id = input("Enter valid application ID: ") 67 | token = input("Enter token: ") 68 | command_id = input("Enter command ID: ") 69 | while not command_id.isdigit(): 70 | command_id = input("Ented valid command ID: ") 71 | cmd_Type = input("[Gl]obal or [G]uild?: ").lower() 72 | 73 | if cmd_Type == "guild" or "gu": 74 | guild_id = input("Enter guild ID: ") 75 | while not guild_id.isdigit(): 76 | guild_id = input("Enter valid guild ID: ") 77 | url = "https://discord.com/api/v8/applications/" + \ 78 | application_id+"/guilds/"+guild_id+"/commands/"+command_id 79 | elif cmd_Type == "global" or "gl": 80 | url = "https://discord.com/api/v8/applications/" + \ 81 | application_id + "/commands/" + command_id 82 | else: 83 | print("Invalid response") 84 | 85 | headers = { 86 | "Authorization": "Bot " + token 87 | } 88 | 89 | r = requests.delete(url, headers=headers) 90 | print(r.content) 91 | if r.status_code == 204: 92 | print("Operation success!") 93 | else: 94 | print("It looks like something went wrong.") 95 | 96 | 97 | def GetCommand(): 98 | application_id = input("Enter application ID: ") 99 | while not application_id.isdigit(): 100 | application_id = input("Enter valid application ID: ") 101 | token = input("Enter bot token: ") 102 | cmd_Type = input("[Gl]obal or [G]uild?: ").lower() 103 | if cmd_Type == "guild": 104 | guild_id = input("Enter guild ID: ") 105 | while not guild_id.isdigit(): 106 | guild_id = input("Enter guild ID: ") 107 | url = "https://discord.com/api/v8/applications/" + \ 108 | application_id+"/guilds/"+guild_id+"/commands" 109 | elif cmd_Type == "global" or "gl": 110 | url = "https://discord.com/api/v8/applications/" + application_id + "/commands" 111 | else: 112 | print("Invalid response") 113 | 114 | headers = { 115 | "Authorization": "Bot " + token 116 | } 117 | r = requests.get(url, headers=headers) 118 | print(r.content) 119 | funcSelector() 120 | 121 | 122 | def funcSelector(): 123 | print("") 124 | print("Please select a function") 125 | print("") 126 | print("To update a command, create a new command with the same name, this will override it.") 127 | print("") 128 | print("[C]reate command") 129 | print("[D]elete command") 130 | print("[G]et commands") 131 | print("") 132 | fSel = input("Enter function: ")[0].lower() 133 | 134 | if fSel == "c": 135 | CreateCommand() 136 | elif fSel == "d": 137 | DeleteCommand() 138 | elif fSel == "g": 139 | GetCommand() 140 | else: 141 | print("Invalid function.") 142 | 143 | 144 | funcSelector() 145 | --------------------------------------------------------------------------------