-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot_discord.py
45 lines (32 loc) · 1.15 KB
/
bot_discord.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
import os
import discord
from dotenv import load_dotenv
from chat import chat
load_dotenv()
private_messages = []
group_messages = []
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
channel = message.channel
content = message.content
type_channel = channel.type
if message.author == self.user:
return
await channel.typing()
if '/gpt ' in content and 'text' in type_channel:
group_messages.append(
{"role": "user", "content": content.replace('/gpt ', '')})
await self.reply(channel, group_messages)
if 'private' in type_channel:
private_messages.append(
{"role": "user", "content": content})
await self.reply(channel, private_messages)
async def reply(self, channel, array):
response = chat(array)
await channel.send(response.choices[0].message.content)
intents = discord.Intents.default()
intents.message_content = True
client = MyClient(intents=intents)
client.run(os.environ.get('DISCORD_KEY'))