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

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

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 Relatório

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