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

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

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 Report

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