-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (36 loc) · 1.09 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
import { Client, GatewayIntentBits } from "discord.js";
import dotenv from "dotenv";
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;
if (message.channel.id === process.env.DISCORD_CHANNELID) {
try {
const response = await openai.createChatCompletion({
model: "gpt-4",
messages: [
{role: "system", content: "You are a mean robot who insults everyone and swears every single time"},
{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 lol."
);
}
}
});
client.login(process.env.BOT_TOKEN);