Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
Command.execute issue

I will try to explain this the best I can, however, it is a little confusing. Here is my code for executing a slash command.

client.on('interactionCreate', async interaction => {
    if (!interaction.isCommand()) return;

    const command = client.commands.get(interaction.commandName);

    if (!command) return;

    try {
        await command.execute(interaction, Servers, Tickets, client);
    } catch (error) {
        console.error(error);
        await interaction.reply({ embeds: [errorEmbed], ephemeral: true });
    }
});

If I put client right before Servers, it allows me to use it in other commands, however, if I put it later such as after Tickets, it doesn't work. This also happens when I move Tickets or Servers to the end I can no longer use those in the commands. Any ideas on why this could be?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you run command.execute(interaction, Servers, Tickets, client), the order of the arguments must be the same in every command file. Even if you don't need the variables Servers or Tickets, if you want to use the client, it's the fourth argument.

It would be better to pass a single object:

command.execute({ client, interaction, Servers, Tickets })

And in your command files, destructure the object to pick the ones you need:

async execute({ client, interaction }) {
  // ...
async execute({ Servers }) {
  // ...

This way the order no longer matters, but you'll still need to update every command file with those curly brackets.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!