-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChatGPTBot.py
52 lines (44 loc) · 1.66 KB
/
ChatGPTBot.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
############################################
# To use this change your bot token and #
# open_api key. #
# #
# TO run this, run main.py #
# #
# This is an EXTREMELY BASIC chat bot that #
# uses openai's apis to carry on a #
# converstaion. #
############################################
import discord
import openai
def run_discord_bot():
botToken = '_YOUR_BOT_TOKEN_HERE_'
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print('------------------')
print(f'ChatGPT bot has logged in as {client.user}')
print(f'latency: {client.latency}')
print(f'user id: {client.user.id}')
print('------------------')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('>'):
prompt = message.content
openai.api_key = '_YOUR_OPEN_API_KEY_HERE_'
response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
temperature=0.9,
max_tokens=150,
top_p=1,
frequency_penalty=0.0,
presence_penalty=0.6,
stop=[" Human:", " AI:"]
)
response_text = response["choices"][0]["text"]
await message.channel.send(response_text)
client.run(botToken)