-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
42 lines (34 loc) · 1011 Bytes
/
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
import dotenv from "dotenv";
import { Client, GatewayIntentBits } from "discord.js";
import { Configuration, OpenAIApi } from "openai";
dotenv.config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
const openai = new OpenAIApi(new Configuration({
apiKey: process.env.OPENAI_API_KEY,
})
);
client.on("messageCreate", async function (message) {
if (message.author.bot) return;
try {
const response = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [
{role: "system", content: "You are a helpful assistant who responds succinctly"},
{role: "user", content: message.content}
],
});
const content = response.data.choices[0].message;
return message.reply(content);
} catch (err) {
return message.reply(
"As an AI robot, I errored out."
);
}
});
client.login(process.env.BOT_TOKEN);