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

308
Vistas
Discord.js v13 (intermediate value).setToken(...) is not a function

Im new to Discod.js v13. I get this error

    (async () => {
    ^

TypeError: (intermediate value) is not a function

This is the code i think its the problem

  const rest = new REST({
        version: "9"
    }).setToken("MyToken")
    (async () => {

If you need the full code:

const { Client, Intents, Collection } = require("discord.js")
const fs = require("fs")
const {REST} = require("@discordjs/rest");
const {Routes} = require("discord-api-types/v9");
const client = new Client({
    intents:[
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MESSAGES
    ]
})
const BotName = "TestBot"

const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));

const commands = []

client.commands = new Collection()

for(const file of commandFiles){
    const command = require("./commands/"+file)
    commands.push(command.data.toJSON());
    client.commands.set(command.data.name, command)
}
client.once("ready", applicationId =>{
    console.log(`${BotName} is now online`)

    const CLIENT_ID = client.user.id

    const rest = new REST({
        version: "9"
    }).setToken("MyToken")
    (async () => {
        try{
            if(process.env.ENV === "production"){
               await rest.put(Routes.applicationCommands(CLIENT_ID), {
                   body: commands
               })
                console.log("Success command register globally")
            }else{
                await rest.put(Routes.applicationGuildCommands(CLIENT_ID, process.env.GUILD_ID), {
                    body: commands
                })
                console.log("Success command register locally")
            }
        }catch(err){
         console.log(err)
        }
    })();
})

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

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

    if(!command) return
    try{
         await command.execute(interaction);
    }catch(err){
        console.log(err)
        await interaction.reply({
            content: "ERROR" + err,
            ephemeral:true
        })
    }
})
client.login("MyToken")
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As said in my comment, this is a ASI (automatic semicolon insertion) related error. I checked it, and after putting a semicolon after }).setToken("MyToken"); it worked fine.

Always use semicolons to avoid these mistakes.

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