Running 2 differents files on the same bot ?

Hello, i have multiple /command on the same Bot, one of them use collectors and i would like to separate this command from all the others to be able to add other simple commands in development without shutdown that collector command. Is someone can tell me if that's possible? (i have a conflict between the both file)
9 Replies
d.js toolkit
d.js toolkit2y ago
• 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.
Elyana
ElyanaOP2y ago
• discord.js :[email protected] • node : v17.3.0
//======> Declare all function files <======//

// add commands collection
client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}

//======> Declare all event <======//

client.on('ready', async c => {

console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.on('interactionCreate', async interaction => {
if (interaction.isChatInputCommand() && interaction.commandName === "fishing") {
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
} else if (interaction.isChatInputCommand() && interaction.commandName === "fishing") {
const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}

try {
await command.autocomplete(interaction);
} catch (error) {
console.error(error);
}
}
});

// connecter le script au bot discord
client.login(process.env.TOKEN);
//======> Declare all function files <======//

// add commands collection
client.commands = new Collection();
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}

//======> Declare all event <======//

client.on('ready', async c => {

console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.on('interactionCreate', async interaction => {
if (interaction.isChatInputCommand() && interaction.commandName === "fishing") {
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
} else if (interaction.isChatInputCommand() && interaction.commandName === "fishing") {
const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}

try {
await command.autocomplete(interaction);
} catch (error) {
console.error(error);
}
}
});

// connecter le script au bot discord
client.login(process.env.TOKEN);
• Explain what exactly your issue is : running 2 script like this. The other one which have a collector, have the condition
if (interaction.isChatInputCommand() && interaction.commandName === "poll")
if (interaction.isChatInputCommand() && interaction.commandName === "poll")
To upload more easily new features for my bot in the future, i would like to separate the "poll" which need to be always online without interruption, But by doing this, when i run /poll, it shutdown the script above by saying that :
DiscordAPIError[40060]: Interaction has already been acknowledged.
at SequentialHandler.runRequest (C:\Users\Propriétaire\Documents\Bot Discord\Vicky\node_modules\@discordjs\rest\dist\index.js:933:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (C:\Users\Propriétaire\Documents\Bot Discord\Vicky\node_modules\@discordjs\rest\dist\index.js:712:14)
at async REST.request (C:\Users\Propriétaire\Documents\Bot Discord\Vicky\node_modules\@discordjs\rest\dist\index.js:1321:22)
at async ChatInputCommandInteraction.reply (C:\Users\Propriétaire\Documents\Bot Discord\Vicky\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
at async Client.<anonymous> (C:\Users\Propriétaire\Documents\Bot Discord\Vicky\vicky-commands.js:70:10)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:251:10)
at processTicksAndRejections (node:internal/process/task_queues:85:21) {
rawError: {
message: 'Interaction has already been acknowledged.',
code: 40060
},
code: 40060,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1104781967985229910/aW50ZXJhY3Rpb246MTEwNDc4MTk2Nzk4NTIyOTkxMDpoU1ZRRmhSUWtUZ0dFY09Ja3NKVEdKTGVrUm82T2ZaWExPYWVJbWFWaWZSUUFVb3lrdGx3WkxPQzNpQ0R4WFVQYTZveGVyOVB6UGY0dzVLZjJXaXhWT3l5SFFkUGhCaVNkUG5nMm96Um9zTmVyY1RUYllHcWE1OXVlUFR0aloxTA/callback',
requestBody: {
files: [],
json: {
type: 4,
content: 'There was an error while executing this command!',
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 64,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
}
}
DiscordAPIError[40060]: Interaction has already been acknowledged.
at SequentialHandler.runRequest (C:\Users\Propriétaire\Documents\Bot Discord\Vicky\node_modules\@discordjs\rest\dist\index.js:933:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (C:\Users\Propriétaire\Documents\Bot Discord\Vicky\node_modules\@discordjs\rest\dist\index.js:712:14)
at async REST.request (C:\Users\Propriétaire\Documents\Bot Discord\Vicky\node_modules\@discordjs\rest\dist\index.js:1321:22)
at async ChatInputCommandInteraction.reply (C:\Users\Propriétaire\Documents\Bot Discord\Vicky\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
at async Client.<anonymous> (C:\Users\Propriétaire\Documents\Bot Discord\Vicky\vicky-commands.js:70:10)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:251:10)
at processTicksAndRejections (node:internal/process/task_queues:85:21) {
rawError: {
message: 'Interaction has already been acknowledged.',
code: 40060
},
code: 40060,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1104781967985229910/aW50ZXJhY3Rpb246MTEwNDc4MTk2Nzk4NTIyOTkxMDpoU1ZRRmhSUWtUZ0dFY09Ja3NKVEdKTGVrUm82T2ZaWExPYWVJbWFWaWZSUUFVb3lrdGx3WkxPQzNpQ0R4WFVQYTZveGVyOVB6UGY0dzVLZjJXaXhWT3l5SFFkUGhCaVNkUG5nMm96Um9zTmVyY1RUYllHcWE1OXVlUFR0aloxTA/callback',
requestBody: {
files: [],
json: {
type: 4,
content: 'There was an error while executing this command!',
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 64,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
}
}
My question is, is that possible to run 2 /commands scripts properly ?
d.js docs
d.js docs2y ago
guide Creating Your Bot: Executing commands When your bot receives a Client#event:interactionCreateopen in new window event, the interaction object contains all the information you need to dynamically retrieve and execute your commands! read more
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Elyana
ElyanaOP2y ago
If i need to implement other commands without shutdown a /slashcommand which hold an active collector ?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Elyana
ElyanaOP2y ago
I mean, if i add other slash command to the client, i need to restart the script to let the bot take those new commands into consideration, no ? But by doing that, the /poll collector will not be active anymore That's why, i try to separate one slash commands from all the others
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Elyana
ElyanaOP2y ago
I see, was seduce by that collectors stuff, easier to maintain and more focus on the messages (ressources save). I will redo my code into the traditional way then
Want results from more Discord servers?
Add your server