forked from JoaquimCassano/CHAT-GPT-Discord-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (27 loc) · 825 Bytes
/
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
import openai
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents) #Change ! to the command prefix you want
client = discord.Client(intents=intents)
@bot.command()
async def chatgpt(ctx, *, msg=''):
# Set up the OpenAI API client
openai.api_key = "api-key" #Change this
inputdiscord = msg
# Set up the model and prompt
model_engine = "text-davinci-003"
prompt = (inputdiscord)
# Generate a response
completion = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
response = completion.choices[0].text
await ctx.send(response)
bot.run('TOKEN') #CHANGE TO YOUR BOT TOKEN