command handler

my code in 01registercommands.js
const { testServer } = require('../../../config.json');
const areCommandsDifferent = require('../../utils/areCommandsDifferent');
const getApplicationCommands = require('../../utils/getApplicationCommands');
const getLocalCommands = require('../../utils/getLocalCommands');

module.exports = async (client) => {

try {
const localCommands = getLocalCommands();
const applicationCommands = await getApplicationCommands(client, testServer);

for (const localCommand of localCommands) {
const { name, description, options } = localCommand;

const existingCommand = await applicationCommands.cache.find(
(cmd) => cmd.name === name
);

if (existingCommand) {
if (localCommand.delted) {
await applicationCommands.delete(existingCommand.id);
continue;
}

if (areCommandsDifferent(existingCommand, localCommand)) {
await applicationCommands.edit(existingCommand.id, {
description,
options,
});
console.log(`Edited command "${name}".`)
}
} else {
if (localCommand.delted) {
console.log(`Skipping registering command "${name}." as it's set to delete.`);
continue;
}

await applicationCommands.create({
name,
description,
options,
})

console.log(`Registered command "${name}."`)
}
}
} catch (error) {
console.log(`There was an error: "${error}"`)
}
};
const { testServer } = require('../../../config.json');
const areCommandsDifferent = require('../../utils/areCommandsDifferent');
const getApplicationCommands = require('../../utils/getApplicationCommands');
const getLocalCommands = require('../../utils/getLocalCommands');

module.exports = async (client) => {

try {
const localCommands = getLocalCommands();
const applicationCommands = await getApplicationCommands(client, testServer);

for (const localCommand of localCommands) {
const { name, description, options } = localCommand;

const existingCommand = await applicationCommands.cache.find(
(cmd) => cmd.name === name
);

if (existingCommand) {
if (localCommand.delted) {
await applicationCommands.delete(existingCommand.id);
continue;
}

if (areCommandsDifferent(existingCommand, localCommand)) {
await applicationCommands.edit(existingCommand.id, {
description,
options,
});
console.log(`Edited command "${name}".`)
}
} else {
if (localCommand.delted) {
console.log(`Skipping registering command "${name}." as it's set to delete.`);
continue;
}

await applicationCommands.create({
name,
description,
options,
})

console.log(`Registered command "${name}."`)
}
}
} catch (error) {
console.log(`There was an error: "${error}"`)
}
};
3 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
f(x) = 1/x
f(x) = 1/xOP9mo ago
the error
[nodemon] 3.1.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,cjs,json
[nodemon] starting `node src/index.js`
[
'C:\\Users\\SWEET HOME\\Desktop\\BTEP\\src\\events\\interactioncreate\\handlecommands.js'
]
[
'C:\\Users\\SWEET HOME\\Desktop\\BTEP\\src\\events\\ready\\01registerCommands.js',
'C:\\Users\\SWEET HOME\\Desktop\\BTEP\\src\\events\\ready\\consoleLog.js'
]
There was an error: "DiscordAPIError[50035]: Invalid Form Body
options[0].description[BASE_TYPE_REQUIRED]: This field is required
options[1].description[BASE_TYPE_REQUIRED]: This field is required"
bot is online
[nodemon] 3.1.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,cjs,json
[nodemon] starting `node src/index.js`
[
'C:\\Users\\SWEET HOME\\Desktop\\BTEP\\src\\events\\interactioncreate\\handlecommands.js'
]
[
'C:\\Users\\SWEET HOME\\Desktop\\BTEP\\src\\events\\ready\\01registerCommands.js',
'C:\\Users\\SWEET HOME\\Desktop\\BTEP\\src\\events\\ready\\consoleLog.js'
]
There was an error: "DiscordAPIError[50035]: Invalid Form Body
options[0].description[BASE_TYPE_REQUIRED]: This field is required
options[1].description[BASE_TYPE_REQUIRED]: This field is required"
bot is online
await applicationCommands.create({
name: 'x',
description: 'y',
options [ ]
})
await applicationCommands.create({
name: 'x',
description: 'y',
options [ ]
})
what should i write in x and y i put it as x and y but it is only registering ban.js and not ping.js
duck
duck9mo ago
this whole system seems completely unnecessary bulk overwriting commands already only updates commands that need to be updated and deletes commands that you don't deploy creating, editing, and deleting them individually would produce far more api calls than is necessary because bulk overwriting can be achieved in 1 api call
Want results from more Discord servers?
Add your server