eternalxty
DIAdiscord.js - Imagine an app
•Created by eternalxty on 10/27/2023 in #djs-questions
Split command
Hello, I'm asking for help because I don't even know how to implement this
I have 2 commands /creative work and /creative action
Keeping them in one file is very inconvenient, and I want to split them into two (something like work.js and action.js)
But here's the problem: when I split it into different files, I get an error
As I understand it, he swears specifically at /creative
So the question is, what needs to be changed in commandHandler and/or deploy so that I can use /creative in different files?
CommandHandler code:
deploy.js code:
Thanks in advance for helping a newbie!
DiscordAPIError[50035]: Invalid Form Body
4[APPLICATION_COMMANDS_DUPLICATE_NAME]: Application command names must be unique
DiscordAPIError[50035]: Invalid Form Body
4[APPLICATION_COMMANDS_DUPLICATE_NAME]: Application command names must be unique
const { readdirSync } = require('fs');
const { log } = require('../functions');
const ExtendedClient = require('../class/ExtendedClient');
/**
*
* @param {ExtendedClient} client
*/
module.exports = (client) => {
for (const type of readdirSync('./src/commands/')) {
for (const dir of readdirSync('./src/commands/' + type)) {
for (const file of readdirSync('./src/commands/' + type + '/' + dir).filter((f) => f.endsWith('.js'))) {
const module = require('../commands/' + type + '/' + dir + '/' + file);
if (!module) continue;
if (type === 'prefix') {
if (!module.structure?.name || !module.run) {
log('Unable to load the command ' + file +' due to missing \'structure#name\' or/and \'run\' properties.', 'warn');
continue;
};
client.collection.prefixcommands.set(module.structure.name, module);
if (module.structure.aliases && Array.isArray(module.structure.aliases)) {
module.structure.aliases.forEach((alias) => {
client.collection.aliases.set(alias, module.structure.name);
});
};
} else {
if (!module.structure?.name || !module.run) {
log('Unable to load the command ' + file +' due to missing \'structure#name\' or/and \'run\' properties.', 'warn');
continue;
};
client.collection.interactioncommands.set(module.structure.name, module);
client.applicationcommandsArray.push(module.structure);
};
log('Loaded new command: ' + file, 'info');
};
};
};
};
const { readdirSync } = require('fs');
const { log } = require('../functions');
const ExtendedClient = require('../class/ExtendedClient');
/**
*
* @param {ExtendedClient} client
*/
module.exports = (client) => {
for (const type of readdirSync('./src/commands/')) {
for (const dir of readdirSync('./src/commands/' + type)) {
for (const file of readdirSync('./src/commands/' + type + '/' + dir).filter((f) => f.endsWith('.js'))) {
const module = require('../commands/' + type + '/' + dir + '/' + file);
if (!module) continue;
if (type === 'prefix') {
if (!module.structure?.name || !module.run) {
log('Unable to load the command ' + file +' due to missing \'structure#name\' or/and \'run\' properties.', 'warn');
continue;
};
client.collection.prefixcommands.set(module.structure.name, module);
if (module.structure.aliases && Array.isArray(module.structure.aliases)) {
module.structure.aliases.forEach((alias) => {
client.collection.aliases.set(alias, module.structure.name);
});
};
} else {
if (!module.structure?.name || !module.run) {
log('Unable to load the command ' + file +' due to missing \'structure#name\' or/and \'run\' properties.', 'warn');
continue;
};
client.collection.interactioncommands.set(module.structure.name, module);
client.applicationcommandsArray.push(module.structure);
};
log('Loaded new command: ' + file, 'info');
};
};
};
};
const { REST, Routes } = require("discord.js");
const { log } = require("../functions");
const config = require("../config");
const ExtendedClient = require('../class/ExtendedClient');
/**
*
* @param {ExtendedClient} client
*/
module.exports = async (client) => {
const rest = new REST({ version: '10' }).setToken(process.env.CLIENT_TOKEN || config.client.token);
try {
log('Started loading application commands... (this might take minutes!)', 'warn');
await rest.put(Routes.applicationCommands(process.env.CLIENT_ID || config.client.id), {
body: client.applicationcommandsArray
});
log('Successfully loaded application commands to Discord API.', 'done');
} catch (e) {
log(`Unable to load application commands to Discord API. ${e}`, 'err');
};
};
const { REST, Routes } = require("discord.js");
const { log } = require("../functions");
const config = require("../config");
const ExtendedClient = require('../class/ExtendedClient');
/**
*
* @param {ExtendedClient} client
*/
module.exports = async (client) => {
const rest = new REST({ version: '10' }).setToken(process.env.CLIENT_TOKEN || config.client.token);
try {
log('Started loading application commands... (this might take minutes!)', 'warn');
await rest.put(Routes.applicationCommands(process.env.CLIENT_ID || config.client.id), {
body: client.applicationcommandsArray
});
log('Successfully loaded application commands to Discord API.', 'done');
} catch (e) {
log(`Unable to load application commands to Discord API. ${e}`, 'err');
};
};
11 replies