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

209
Vistas
not being able to initialize REST object in discord.js

I am currently trying to make a simple discord bot following the discord.js documentation.(https://discordjs.guide/creating-your-bot/creating-commands.html#command-deployment-script) My issue is regarding the deploy-command.js file:

const {SlashCommandBuilder} = require('@discordjs/builders')
const {Routes} = require('discord-api-types/v9')
const dotenv = require('dotenv')
const {REST} = require("@discordjs/rest");

dotenv.config()
const token = process.env.DISCORD_JS_TOKEN
const clientId = process.env.clientId
const guildId = process.env.guildId

const commands = [
    new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!'),
    new SlashCommandBuilder().setName('server').setDescription('Replies with server info!'),
    new SlashCommandBuilder().setName('user').setDescription('Replies with user info!')
].map(command => command.toJSON())

const rest = new REST({version:'9'}).setToken(token)

rest.put(Routes.applicationGuildCommands(clientId,guildId),{body:commands})
    .then(() => console.log("Successfully registered application commands from file"))
    .catch(() => console.log('error happened'))

I'm getting an error at the following line:

const rest = new REST({version:'9'}).setToken(token) ---> Interface cannot be instantiated

I've tried removing package-lock.json and node_modules and then reinstalling them via "npm install", that didn't have any effect. There is a REST interface and a REST class in the discordjs/rest module. While hovering over the {version:'9'}, I'm getting the following message: "Invalid number of arguments, expected 0" and the suggestion to "create constructor in class rest"(which there already is one, for the REST class)

This issue has been extremly frustrating as I can't seem to find anyone else that had a similar issue and all the videos I've watched on youtube execute the exact same code with no issues(only difference being that they use visual studio code in the videos).

Any help would be appreciated.

software used:

nodejs(tried version 16.6.0 and 17.0.0)

webstorm 2021.2.2

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I had the exact same issue and then tried it on VS Code and it perfectly worked. I have no idea so far as to why it does not work in Webstorm though...

about 4 years ago · Juan Pablo Isaza Denunciar

0

Ive came across the same issue. For anyone whos coming across this thread and has the same issue, i found out that i was using the wrong Client ID. i was using my personal Client ID instead of the ClientID of the Bot found in the discord developer portal.

The documentation doesn't clearly state this annoyingly

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