Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

344
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda