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

354
Views
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 answers
Answer question

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 Report

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 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!