Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

340
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda