87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
const {
|
|
Client,
|
|
Collection,
|
|
GatewayIntentBits,
|
|
Partials,
|
|
REST,
|
|
Routes,
|
|
} = require("discord.js");
|
|
require("dotenv").config();
|
|
const { sendLog } = require("./libs/logs.js");
|
|
|
|
const client = new Client({
|
|
intents: [
|
|
GatewayIntentBits.Guilds,
|
|
GatewayIntentBits.GuildMessages,
|
|
GatewayIntentBits.DirectMessages,
|
|
GatewayIntentBits.MessageContent,
|
|
],
|
|
partials: [Partials.Channel, Partials.Message],
|
|
});
|
|
|
|
client.commands = new Collection();
|
|
const commands = [];
|
|
const foldersPath = path.join(__dirname, "commands");
|
|
const commandFolders = fs.readdirSync(foldersPath);
|
|
|
|
for (const folder of commandFolders) {
|
|
const commandsPath = path.join(foldersPath, folder);
|
|
const commandFiles = fs
|
|
.readdirSync(commandsPath)
|
|
.filter((file) => file.endsWith(".js"));
|
|
|
|
for (const file of commandFiles) {
|
|
const filePath = path.join(commandsPath, file);
|
|
const command = require(filePath);
|
|
if ("data" in command && "execute" in command) {
|
|
client.commands.set(command.data.name, command);
|
|
commands.push(command.data.toJSON());
|
|
} else {
|
|
console.log(
|
|
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
const rest = new REST().setToken(process.env.DISCORD_TOKEN);
|
|
|
|
(async () => {
|
|
try {
|
|
console.log(
|
|
`Started refreshing ${commands.length} application (/) commands.`
|
|
);
|
|
sendLog(`Started refreshing ${commands.length} application (/) commands.`);
|
|
|
|
const data = await rest.put(
|
|
Routes.applicationCommands(process.env.BOT_ID),
|
|
{ body: commands }
|
|
);
|
|
|
|
console.log(
|
|
`Successfully reloaded ${data.length} application (/) commands.`
|
|
);
|
|
sendLog(`Successfully reloaded ${data.length} application (/) commands.`);
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
})();
|
|
|
|
const eventsPath = path.join(__dirname, "events");
|
|
const eventFiles = fs
|
|
.readdirSync(eventsPath)
|
|
.filter((file) => file.endsWith(".js"));
|
|
|
|
for (const file of eventFiles) {
|
|
const filePath = path.join(eventsPath, file);
|
|
const event = require(filePath);
|
|
if (event.once) {
|
|
client.once(event.name, (...args) => event.execute(...args));
|
|
} else {
|
|
client.on(event.name, (...args) => event.execute(...args));
|
|
}
|
|
}
|
|
|
|
client.login(process.env.DISCORD_TOKEN);
|