-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
75 lines (57 loc) · 2.03 KB
/
app.py
File metadata and controls
75 lines (57 loc) · 2.03 KB
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
# from dotenv import load_dotenv
from gptbots import davinci_client
import os
import traceback
import nextcord
# from nextcord import app_commands
from nextcord.ext import commands
# import logging
print("Starting up.")
intents = nextcord.Intents(messages=True)
# Send messages
async def send_message(message, user_message, is_private):
# try:
# await message.channel.trigger_typing()
# response = davinci_client.handle_response(user_message)
async with message.channel.typing():
response = davinci_client.handle_response(user_message)
if is_private:
reply = await message.author.send(response)
else:
reply = await message.channel.send(response)
def test_message():
print("Firing off test message:")
# msg = gpt_chat_client.handle_response("Are you working?")
msg = davinci_client.handle_response("You're alive now. Greet the world.")
print(msg)
test_message()
def run_discord_bot():
print("Setting up bot.")
# Change your token here
# load_dotenv()
TOKEN = os.getenv("DISCORD_BOT_TOKEN")
client = nextcord.Client(intents=intents)
# tree = app_commands.CommandTree(client)
# @tree.command(name="chatgpt", description="Use ChatGPT")
# async def chat(interaction):
# await interaction.response.send_message("Hello!")
async def on_ready():
# await tree.sync()
print(f'{client.user} is now running!')
@client.event
async def on_message(message):
if message.author == client.user:
return
username = str(message.author)
user_message = str(message.content)
channel = str(message.channel)
if len(user_message) == 0:
return
print(f"{username} said: '{user_message}' ({channel})")
if user_message[0] == '?':
user_message = user_message[1:]
await send_message(message, user_message, is_private=True)
else:
await send_message(message, user_message, is_private=False)
client.run(TOKEN)
run_discord_bot()