forked from shaobo9856/Discord-bot-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
47 lines (32 loc) · 1.05 KB
/
main.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
import os
import discord
import requests
from discord import app_commands
API_URL = os.environ["URL"]
headers = {"Authorization": os.environ["API_KEY"]}
my_secret = os.environ['DISCORD_BOT_SECRET']
class CustomClient(discord.Client):
def __init__(self, *, intents: discord.Intents):
super().__init__(intents=intents)
self.tree = app_commands.CommandTree(self)
async def setup_hook(self):
await self.tree.sync()
client = CustomClient(intents=discord.Intents.all())
def query(payload):
try:
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
except Exception as e:
return {"error": str(e)}
@client.event
async def on_ready():
print("I'm in")
print(client.user)
@client.tree.command(name="ask", description="Ask a question to AbyssBot")
async def ask(interaction: discord.Interaction, question: str):
await interaction.response.defer()
print("Player:",question)
output = query({"question": question})
print("Bot:",output)
await interaction.followup.send(output)
client.run(my_secret)