File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ import aiohttp
2+
3+
4+ async def add_slash_command (bot_id ,
5+ bot_token : str ,
6+ guild_id ,
7+ cmd_name : str ,
8+ description : str ,
9+ options : list = None ):
10+ url = f"https://discord.com/api/v8/applications/{ bot_id } "
11+ url += "/commands" if guild_id else f"/guilds/{ guild_id } /commands"
12+ base = {
13+ "name" : cmd_name ,
14+ "description" : description ,
15+ "options" : options if options else []
16+ }
17+
18+ async with aiohttp .ClientSession () as session :
19+ async with session .post (url , headers = {"Authorization" : f"Bot { bot_token } " }, json = base ) as resp :
20+ return await resp .json ()
21+
22+
23+ async def remove_slash_command (bot_id ,
24+ bot_token ,
25+ guild_id ,
26+ cmd_id ):
27+ url = f"https://discord.com/api/v8/applications/{ bot_id } "
28+ url += "/commands" if guild_id else f"/guilds/{ guild_id } /commands"
29+ url += f"/{ cmd_id } "
30+ async with aiohttp .ClientSession () as session :
31+ async with session .delete (url , headers = {"Authorization" : f"Bot { bot_token } " }) as resp :
32+ return resp .status
33+
34+
35+ def create_option (name : str ,
36+ description : str ,
37+ option_type : int ,
38+ required : bool ,
39+ choices : list = None ):
40+ return {
41+ "name" : name ,
42+ "description" : description ,
43+ "type" : option_type ,
44+ "required" : required ,
45+ "choices" : choices if choices else []
46+ }
47+
48+
49+ def create_choices (value : str , description : str ):
50+ return {
51+ "value" : value ,
52+ "name" : description
53+ }
You can’t perform that action at this time.
0 commit comments