-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (54 loc) · 2.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { Client, GatewayIntentBits } = require('discord.js');
const { generate } = require('./ai-service.js');
const dotenv = require("dotenv");
dotenv.config();
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
// give permission to send reply
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
client.guilds.cache.forEach(guild => {
guild.commands.create({
name: 'ask',
description: 'Replies with answer to your question',
options: [
{
name: 'q',
description: 'The question you want to ask',
type: 3,
required: true,
},
],
});
});
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
const { commandName, options } = interaction;
if (commandName === 'ask') {
const question = options.getString('q');
await interaction.deferReply();
try {
const res = await generate(question);
// Send the actual response
await interaction.followUp(res.response);
} catch (error) {
console.error('Error generating response:', error);
await interaction.followUp('There was an error processing your request.');
}
}
});
client.on('messageCreate', async message => {
// Ignore messages from bots
if (message.author.bot) return;
// Ignore messages that don't mention the bot
if (!message.mentions.has(client.user)) return;
console.log('metioned')
// come up with good line when someone metions you in chat
const res = await generate(`someone mentioned you in chat. a short witty reply. don't use quotes. be more like human altough you are not`)
try {
message.reply(res.response);
} catch {
message.reply('There was an error processing your request.');
}
})
client.login(process.env.BOT_TOKEN);