-
Notifications
You must be signed in to change notification settings - Fork 2
/
discord-slash-commands.py
144 lines (120 loc) · 4.42 KB
/
discord-slash-commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# 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.
import requests
def CreateCommand():
application_id = input("Enter application ID: ")
while not application_id.isdigit():
application_id = input("Enter application ID: ")
token = input("Enter bot token: ")
cmdType = input("[Gl]obal or [G]uild?: ").lower()
if cmdType == "global" or "gl":
url = "https://discord.com/api/v8/applications/"+application_id+"/commands"
elif cmdType == "guild" or "gu":
guild_id = input("Enter guild ID: ")
while not guild_id.isdigit():
guild_id = input("Enter guild ID: ")
url = "https://discord.com/api/v8/applications/" + \
application_id+"/guilds/"+guild_id+"/commands"
else:
print("Please choose a valid option.")
cmd_name = input("Enter command name: ")
cmd_description = input("Enter command description: ")
value_name = input("Value name: ")
value_description = input("Value description: ")
#cmd_Type = input("Enter command type (integer): ")
cmd_isRequired = input("Is the command required? (True/False): ")
cmd_isRequired = bool(cmd_isRequired)
# while not cmd_Type.isdigit():
# cmd_Type = input("Enter command type (integer): ")
#cmd_Type = int(cmd_Type)
print("Starting choices editor...")
json = {
"name": cmd_name,
"description": cmd_description,
"options": [
{
"name": value_name,
"description": value_description,
"type": 3,
"required": cmd_isRequired,
},
]
}
headers = {
"Authorization": "Bot " + token
}
print(json)
print(headers)
r = requests.post(url, headers=headers, json=json)
print(r.content)
funcSelector()
def DeleteCommand():
application_id = input("Enter application ID: ")
while not application_id.isdigit():
application_id = input("Enter valid application ID: ")
token = input("Enter token: ")
command_id = input("Enter command ID: ")
while not command_id.isdigit():
command_id = input("Ented valid command ID: ")
cmd_Type = input("[Gl]obal or [G]uild?: ").lower()
if cmd_Type == "guild" or "gu":
guild_id = input("Enter guild ID: ")
while not guild_id.isdigit():
guild_id = input("Enter valid guild ID: ")
url = "https://discord.com/api/v8/applications/" + \
application_id+"/guilds/"+guild_id+"/commands/"+command_id
elif cmd_Type == "global" or "gl":
url = "https://discord.com/api/v8/applications/" + \
application_id + "/commands/" + command_id
else:
print("Invalid response")
headers = {
"Authorization": "Bot " + token
}
r = requests.delete(url, headers=headers)
print(r.content)
if r.status_code == 204:
print("Operation success!")
else:
print("It looks like something went wrong.")
def GetCommand():
application_id = input("Enter application ID: ")
while not application_id.isdigit():
application_id = input("Enter valid application ID: ")
token = input("Enter bot token: ")
cmd_Type = input("[Gl]obal or [G]uild?: ").lower()
if cmd_Type == "guild":
guild_id = input("Enter guild ID: ")
while not guild_id.isdigit():
guild_id = input("Enter guild ID: ")
url = "https://discord.com/api/v8/applications/" + \
application_id+"/guilds/"+guild_id+"/commands"
elif cmd_Type == "global" or "gl":
url = "https://discord.com/api/v8/applications/" + application_id + "/commands"
else:
print("Invalid response")
headers = {
"Authorization": "Bot " + token
}
r = requests.get(url, headers=headers)
print(r.content)
funcSelector()
def funcSelector():
print("")
print("Please select a function")
print("")
print("To update a command, create a new command with the same name, this will override it.")
print("")
print("[C]reate command")
print("[D]elete command")
print("[G]et commands")
print("")
fSel = input("Enter function: ")[0].lower()
if fSel == "c":
CreateCommand()
elif fSel == "d":
DeleteCommand()
elif fSel == "g":
GetCommand()
else:
print("Invalid function.")
funcSelector()