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

339
Views
Discord.js v13, issue with asynchronous code

So my problem is that despite using async functions, my code will still behave like synchronous code. And so some commands are not passing through or are greatly delayed which they clearly shouldn't.

This is the code being executed on the "interactionCreate" event:

const Discord = require("discord.js");

/**
 * 
 * @param {Discord.Client} client 
 * @param {Discord.Interaction} interaction 
 * @returns 
 */
module.exports = async (client, interaction) => {
    if (interaction.isCommand()) {
        const { commandName } = interaction;

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

        if (command) command.execute(client, interaction);
    }
}

And here is a command:

const Discord = require('discord.js');
const util = require('util');
const search = util.promisify(require('g-i-s'));
const Colors = require("../src/colors");

module.exports = {
    name: "salmon",
    description: "Sends a random picture of a salmon",
    /**
    * 
    * @param {Discord.Client} client 
    * @param {Discord.CommandInteraction} interaction 
    */
    async execute(client, interaction) {
        await interaction.deferReply();

        const results = await search("salmon");

        const number = Math.floor(Math.random() * results.length)
        const embed= new Discord.MessageEmbed()
            .setColor(Colors.PINK)
            .setTitle(`Salmon number ${number}.`)
            .setImage(results[number].url);

        interaction.editReply({ embeds: [embed] });
    }
}

Executing the code above will create "lag" on other commands. Which would not really be an issue for me normally but this it impacting the entire code, thus using a "Play music" command very unstable as each time someone will use a command being a little load heavy, an audible lag will be heard.

I had done test with a more heavy load to make the lag stay longer and the bot was not proceeding new commands. Although I feel like I did not do anything wrong. Why is my async execute function not behaving like an async function? Or am I missing something ?

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

0

Maybe you should try to use execute async instead of async execute

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!