-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (66 loc) · 2.74 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
80
81
const { Client, GatewayIntentBits, REST, ActivityType } = require('discord.js');
const { Routes } = require('discord-api-types/v10');
const { readdirSync, readFileSync } = require('fs');
const { SlashCommandBuilder } = require('@discordjs/builders');
const token = "";
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
const pink = '\x1b[95m';
const green = '\x1b[92m';
const blue = '\x1b[34m';
const gray = '\x1b[90m';
const red = '\x1b[91m';
const reset = '\x1b[0m';
const commands = [];
client.once('ready', async () => {
console.log(`${green}(+) Logged in as ${client.user.tag}${reset}`);
try {
client.user.setPresence({
activities: [{ name: 'Game Site Owners', type: ActivityType.Streaming, url: 'https://twitch.tv/discord' }],
status: 'online',
});
const commandFiles = readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
try {
const command = require(`./commands/${file}`);
if (command.data instanceof SlashCommandBuilder) {
commands.push(command.data.toJSON());
}
} catch (error) {
console.error(`${red}(+) Error loading ${file}:${reset}`, error);
}
}
const rest = new REST({ version: '10' }).setToken(token);
const commandsPayload = commands.map(command => ({ name: command.name, description: command.description, options: command.options }));
await rest.put(
Routes.applicationGuildCommands("1209066635777015878", "1208852467891314798"),
{ body: [...commands] },
);
} catch (error) {
console.error(`${red}(+) Error during initialization:${reset}`, error);
}
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand() && !interaction.isButton() && !interaction.isStringSelectMenu() && !interaction.isMessageComponent() &&!interaction.isModalSubmit()) return;
try {
if (interaction.isCommand()) {
const commandFile = `./commands/${interaction.commandName}.js`;
const command = require(commandFile);
command.execute(interaction);
} else {
const componentFile = `./components/${interaction.customId}.js`;
const componentData = require(componentFile);
componentData.execute(interaction);
}
} catch (error) {
console.error(`${red}(+) Error during interaction handling:${reset}`, error);
interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
});
client.login(token);