-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (23 loc) · 1.15 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
// Require
const { Client, GatewayIntentBits } = require("discord.js");
const { Configuration, OpenAIApi } = require("openai");
const { token, apiKey } = require("./config.json");
// Constants
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
const openAI = new OpenAIApi(new Configuration({ apiKey: apiKey }));
const messages = [];
// Client events
client.once("ready", () => {
client.user.setActivity("New AI", { type: "PLAYING" });
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("messageCreate", async message => {
if (message.author.bot) return;
messages.push({ role: "user", content: message.content });
console.log(`${message.member.displayName} : ${message.content}`);
const completion = await openAI.createChatCompletion({ model: "gpt-3.5-turbo", messages: messages });
messages.push({ role: "assistant", content: completion.data.choices[0].message.content });
console.log(`New AI : ${completion.data.choices[0].message.content}`);
await message.channel.send(completion.data.choices[0].message.content);
});
client.login(token);