Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Discord.js v13 / command handler

const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const clientId = 'Your Client ID';
const guildId = 'Your Guild ID';

module.exports = (client) => {
    client.handlecommands = async (commandFolders, path) => {
        client.commandArray = [];
        for (folder of commandFolders) {
            const commandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));

            for (const file of commandFiles) {
                const command = require(`../(Your path to your commands)/${folder}/${file}`);
                client.commands.set(command.data.name, command);
                client.commandArray.push(command.data.toJSON());
            }
        }

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

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

                await rest.put(
                    Routes.applicationGuildCommands(clientId, guildId),
                    { body: client.commandArray },
                );

                console.log('Successfully reloaded application (/) commands.');
            } catch (error) {
                console.error(error);
            }
        })();
         console.log(client.commandArray)
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript identifiers 
Javascript :: schema knex.js 
Javascript :: javascipt async 
Javascript :: js callback hell 
Javascript :: add class to new element javascript 
Javascript :: mongoose max record 
Javascript :: sliding puzzle javascript 
Javascript :: dot notation vs bracket notation 
Javascript :: download file using javascript 
Javascript :: javascript grpc timestamp 
Javascript :: eval javascript 
Javascript :: javascript regex insert string 
Javascript :: js string includes count 
Javascript :: javascript number and math 
Javascript :: change form value dynamically angular 
Javascript :: what is const in javascript 
Javascript :: about ajax 
Javascript :: nodejs: router by use express and path package 
Javascript :: react return value from component 
Javascript :: arcgis for javascript 
Javascript :: data types in js 
Javascript :: js rename property 
Javascript :: define component react with default props and props type 
Javascript :: how to dockerize a node app 
Javascript :: file upload in node js 
Javascript :: javascript weakmap 
Javascript :: repeat pattern regex 
Javascript :: string in js 
Javascript :: timezone in react js 
Javascript :: datatables add row with id 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =