forked from cyclic-software/starter-discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (41 loc) · 1.35 KB
/
index.js
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
require('dotenv').config();
const express = require('express');
const app = express();
const {Client,GatewayIntentBits} = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
const {Configuration, OpenAIApi} = require('openai');
const configration = new Configuration({
organization: process.env.OPENAI_ORG,
apiKey: process.env.OPENAI_KEY
});
const openai = new OpenAIApi(configration);
client.on('messageCreate',async function (message) {
try{
if(message.channel.id !== "1067001774059298846") return;
if(message.author.bot) return;
const gptResponse = await openai.createCompletion({
model: "text-davinci-003",
prompt:`ChatGPT is a friendy chatbot.\n\
ChatGPT: Hello how are you?\n\
${message.author.username}:${message.content}\n\
ChatGPT:}`,
temperature:0.9,
max_tokens:100,
stop:["ChatGPT","Adian Twarog:"]
});
console.log(gptResponse.data.choices);
message.reply(`${gptResponse.data.choices[0].text}`);
}catch(error){
console.log(error)
}
});
client.login(process.env.DISCORD_TOKEN);
app.listen(8999, () => {
console.log("ChatGPT Bot is Online On Discord");
})