-
Notifications
You must be signed in to change notification settings - Fork 0
/
slash.py
110 lines (93 loc) · 2.94 KB
/
slash.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
"""
post a new slash command to a discord endpoint
uses application id and bot token
"""
import os
import json
from typing import Dict
import requests
def post_slash_command(request_json: Dict[str, any], application_id: str, token: str):
url = f"https://discord.com/api/v8/applications/{application_id}/commands"
headers = {
"Authorization": f"Bot {token}"
}
response = requests.post(url, headers=headers, json=request_json)
print(json.loads(response.content))
if __name__ == "__main__":
try:
from dotenv import load_dotenv
load_dotenv()
except ImportError as e:
pass
discord_application_id = os.environ.get('DISCORD_APPLICATION_ID')
discord_token = os.environ.get('DISCORD_BOT_TOKEN')
if discord_application_id is None:
discord_application_id = input("discord application id: ")
if discord_token is None:
discord_token = input("discord bot token: ")
lyrics_json = {
"name": "lyrics",
"type": 1,
"description": "sing like this artist",
"options": [
{
"name": "artist",
"description": "the name of the artist",
"type": 3,
"required": True,
},
{
"name": "artistic_license",
"description": "how creative to make the response",
"type": 10,
"required": False,
"min_value": 0.0,
"max_value": 1.0,
}
]
}
ramble_json = {
"name": "ramble",
"type": 1,
"description": "regale us with a take",
"options": [
{
"name": "prompt",
"description": "kinda going off of what you said...",
"type": 3,
"required": False,
},
{
"name": "artistic_license",
"description": "how creative to make the response",
"type": 10,
"required": False,
"min_value": 0.0,
"max_value": 1.0,
}
]
}
tweet_json = {
"name": "tweet",
"type": 1,
"description": "what would @{username} think about this",
"options": [
{
"name": "username",
"description": "twitter handle",
"type": 3,
"required": True,
},
{
"name": "artistic_license",
"description": "how creative to make the response",
"type": 10,
"required": False,
"min_value": 0.0,
"max_value": 1.0,
}
]
}
post_slash_command(lyrics_json, discord_application_id, discord_token)
post_slash_command(ramble_json, discord_application_id, discord_token)
post_slash_command(tweet_json, discord_application_id, discord_token)