-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (53 loc) · 1.92 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
70
71
72
73
74
75
76
77
78
79
const { token } = require('./config.json');
// Express Server (for WG API)
const express = require('express');
//const fetch = require('node-fetch');
const app = express();
const port = process.env.PORT || 8000;
app.get('*', (req, res) => {
res.send('WG Discord Bot');
});
app.listen(port, function () {
console.log("API Server is running on "+ port +" port");
});
// Discord Bot
const fs = require('fs');
const { Client, Collection, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
client.once('ready', () => {
client.user.setActivity('/wg', { type: 'LISTENING' });
});
client.on('interactionCreate', async interaction => {
if(interaction.isCommand()) {
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction, interaction.options.getString('name'));
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
} else if(interaction.isSelectMenu()){
if(interaction.customId == 'referenced-content'){
if(interaction.values.length > 0){
let valueParts = interaction.values[0].split(':::');
let type = valueParts[0];
let name = valueParts[1];
const command = client.commands.get(type);
try {
await command.execute(interaction, name);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
}
}
});
client.login(token);