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

358
Visualizações
TypeError: async is not a function

I'm doing a slash command handler using discord.js, and I'm getting the "not a function" error. I saw other questions here and some videos on YouTube but I still couldn't solve the problem

This is the code

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

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

    if (!command) return
}))

And this is the error

client.on('interactionCreate', async (interaction => {
                               ^

TypeError: async is not a function
    at Object.<anonymous> (C:\Users\...\Desktop\...\...\...\index.js:60:32)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

I have tried: npm i async and var async = require('async')

Before I created the variable the error was that async was not defined but now it shows this new error

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You misplaced a ")"

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

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

  if (!command) return;
});
about 4 years ago · Juan Pablo Isaza Relatório

0

You are calling client.on('interactionCreate', f ) where f is represented as:

async (interaction => {
    if (!interaction.isCommand()) return

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

    if (!command) return
})

JavaScript is interpreting this as async( ... ).

You can either remove the parentheses surrounding your function, or move the closing parentheses to the end of the arguments of your arrow function.

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

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

    if (!command) return
})

OR

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

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

    if (!command) return
})
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