const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require('fs');
client.commands = new Discord.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.name, command);
}
const fs = require("node:fs");
const path = require("node:path");
const jsonc = require("jsonc");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord.js");
const { token } = require("../../config/token.json");
module.exports = {
/**
* @param {Discord.Client} client
*/
async deployCommands() {
const commands = [];
const commandsPath = path.join(__dirname, "../../commands");
const commandFiles = fs.readdirSync(commandsPath).filter((file) => file.endsWith(".js"));
const { clientId, guildId } = jsonc.parse(fs.readFileSync(path.join(__dirname, "../../config/config.jsonc"), "utf8"));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: "10" }).setToken(token);
rest
.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
.then(() => console.log("✅ Successfully registered application commands."))
.catch(console.error);
},
};
const fs = require("fs-extra");
const path = require("path");
const jsonc = require("jsonc");
const { deployCommands } = require("../misc/deploy-commands.js");
module.exports = {
name: "ready",
once: true,
/**
* @param {import("discord.js").Client} client
*/
execute(client) {
const { activity } = jsonc.parse(
fs.readFileSync(path.join(__dirname, "../../config/config.jsonc"), "utf8")
);
console.log(`Logged in as ${client.user.tag}`);
client.user.setActivity(activity);
deployCommands();
},
};