-
Notifications
You must be signed in to change notification settings - Fork 0
/
sarahBot.py
46 lines (36 loc) · 1.27 KB
/
sarahBot.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
import os
import discord
import openai
from keep_alive import keep_alive
import requests
import json
intents = discord.Intents.all()
client = discord.Client(intents=intents)
openai.api_key = os.environ['OPEN_AI_KEY']
def getRandomCompliment():
response = requests.get("https://complimentr.com/api")
json_data = json.loads(response.text)
compliment = json_data['compliment']
return compliment
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
m = message.content
if message.author == client.user:
return
if message.content.startswith('!hello'):
await message.channel.send('Hello ' + message.author.name + ", " +
getRandomCompliment())
elif message.content.startswith('!help'):
await message.channel.send(
'I will respond to you if you start your sentence with "!"')
elif message.content.startswith('!'):
response = openai.Completion.create(model="text-curie-001",
prompt=m[1:],
temperature=0,
max_tokens=65)
await message.channel.send(response.choices[0].text)
keep_alive()
client.run(os.environ['TOKEN'])