Skip to content
This repository was archived by the owner on Sep 28, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions functions/handelCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@ module.exports = (client) => {

(async () => {
try {
console.log(`[${client.shard.ids}] Started refreshing application (/) commands.`);

const data = await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID), {
body: client.commandArray
},
);
const data = await rest.get(Routes.applicationCommands(process.env.CLIENT_ID), {
query: new URLSearchParams({
with_localizations: true
})
});

client.commandsData = data;

console.log(`[${client.shard.ids}] Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v10");
const express = require("express");
const cors = require("cors");
const handleCommands = require("./utils/commands");

const package = require("./package.json");

require("dotenv").config();

// Register Bot Commands
handleCommands();

// Sharding Manager
const manager = new ShardingManager("bot.js", {
token: process.env.TOKEN,
Expand Down
45 changes: 45 additions & 0 deletions utils/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { Collection, REST } = require("discord.js");
const { Routes } = require("discord-api-types/v10");
const fs = require("fs");

module.exports = async function () {
const commandFolders = fs.readdirSync("./commands");
const commands = new Collection();
const commandArray = [];
const commandNames = new Set();
for (const folder of commandFolders) {
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`../commands/${folder}/${file}`);
const commandName = command.data.name;

if (commandNames.has(commandName)) {
console.error(`Duplicate command name found: ${commandName}`);
continue;
}

commandNames.add(commandName);
commands.set(commandName, command);
commandArray.push(command.data.toJSON());
}
}

const rest = new REST({
version: "10"
}).setToken(process.env.TOKEN);

(async () => {
try {
console.log("Started refreshing application (/) commands.");

const data = await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID), {
body: commandArray
});

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();
};