-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (26 loc) · 1.01 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
let DiscordBotTOKEN = "TOKEN"
let OpenAIAPIKey = "OPENAPIKEY"
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: OpenAIAPIKey,
});
const openai = new OpenAIApi(configuration);
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on("messageCreate", async (msg) => {
if(msg.author.bot) return
if(!msg.mentions.has(client.user)) return
msg.content = msg.content.replace(/<@\d+>/g, "")
let response = await msg.reply("Generating response...")
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: msg.content,
max_tokens: 200,
user: msg.author.id.toString(),
});
response.edit(completion.data.choices[0].text)
})
client.login(DiscordBotTOKEN)