-
Notifications
You must be signed in to change notification settings - Fork 5
/
bot.js
45 lines (40 loc) · 1.23 KB
/
bot.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
import { Client, GatewayIntentBits } from "discord.js";
import { ChatGPT } from "discord-chat-gpt";
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
allowedMentions: {
repliedUser: false,
},
});
const chatGpt = new ChatGPT({
apiKey: `OPEN_AI_KEY`, // get from https://beta.openai.com/account/api-keys
orgKey: `Organization_ID`, // get from https://beta.openai.com/account/org-settings
});
client.on("ready", () => {
console.log(`> ${client.user.username} is Online !!`);
});
client.on("messageCreate", async (message) => {
if (!message.guild || message.author.bot) return;
let ChatBotChannelId = "ChannelID";
let channel = message.guild.channels.cache.get(ChatBotChannelId);
if (!channel) return;
if (message.channel.id === channel.id) {
let msg = await message.reply({
content: `Waiting ....`,
});
let chatreply = await chatGpt
.chat(message.content, message.author.username)
.catch((e) => {
console.log(e);
});
msg.edit({
content: `${chatreply}`,
});
}
});
client.login("BOT_TOKEN");