Skip to content

Commit 1ef83d1

Browse files
committed
Added utils
1 parent 90a8ee4 commit 1ef83d1

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

0 commit comments

Comments
 (0)