#[SOLVED] Help with deployment?

9 messages · Page 1 of 1 (latest)

compact wasp
#

How do I deploy commands to all servers? From what I found it is like below, but from what i can tell, that just deploys to one server as it asks for 1 guildID suggesting it is only deploying to one server. Any help is appreciated.

const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('node:fs');

const commands = [];
// Grab all the command files from the commands directory you created earlier
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    commands.push(command.data.toJSON());
}

// Construct and prepare an instance of the REST module
const rest = new REST({ version: '10' }).setToken(token);

// and deploy your commands!
(async () => {
    try {
        console.log(`Started refreshing ${commands.length} application (/) commands.`);

        // The put method is used to fully refresh all commands in the guild with the current set
        const data = await rest.put(
            Routes.applicationGuildCommands(clientId, guildId),
            { body: commands },
        );

        console.log(`Successfully reloaded ${data.length} application (/) commands.`);
    } catch (error) {
        // And of course, make sure you catch and log any errors!
        console.error(error);
    }
})();
hidden pivot
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

digital sedge
#

Use global commands
Routes.applicationCommands(clientId)

compact wasp
#

ok

#

Uncaught Error Error: ENOENT: no such file or directory, scandir './slash-commands'

compact wasp
#

I have done this:

const dotenv = require('dotenv').config();
const Bot_Token = process.env.Bot_Token;
const clientId = process.env.Client_Id;
const { REST, Routes } = require('discord.js');
const fs = require('node:fs');

const commands = [];
// Grab all the command files from the slash-commands directory you created earlier
const commandFiles = fs.readdirSync(__dirname+'/slash-commands/').filter(file => file.endsWith('.js'));

// Grab the SlashCommandBuilder#toJSON() output of each slash-commands's data for deployment
for (const file of commandFiles) {
    const command = require(__dirname+'/slash-commands/'+file);
    commands.push(command.data.toJSON());
}

// Construct and prepare an instance of the REST module
const rest = new REST({ version: '10' }).setToken(Bot_Token);

// and deploy your slash-commands!
(async () => {
    try {
        console.log(`Started refreshing ${commands.length} application (/) commands.`);

        // The put method is used to fully refresh all slash-commands in the guild with the current set
        const data = await rest.put(
            Routes.applicationCommands(clientId),
            //Routes.applicationGuildCommands(clientId, guildId),
            { body: commands },
        );

        console.log(`Successfully reloaded ${data.length} application (/) commands.`);
    } catch (error) {
        // And of course, make sure you catch and log any errors!
        console.error(error);
    }
})();

If there is a better way of doing it lmk.

kindred bramble
#

That’s a perfectly valid way to circumvent fs being based on cwd you run the script from while require is based on directory the script is in…