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