Search code examples
discord.js

discrod.js REST is not a constructor


const config = require("./config.json");
const Discord = require('discord.js');
const { Intents } = Discord;
const client = new Discord.Client({ 
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] 
})
const { REST, Routes } = require('discord.js');
const commands = [
  {
    name: 'test',
    description: 'test',
  },
];
const rest = new REST({ version: '10' }).setToken(config.BOT_TOKEN);
(async () => {
  try {
    console.log('Started refreshing application (/) commands.');

    await rest.put(Routes.applicationCommands(config.CLIENT_ID), { body: commands });

    console.log('Successfully reloaded application (/) commands.');
  } catch (error) {
    console.error(error);
  }
})();
client.on('interactionCreate', async interaction => {
  if (!interaction.isChatInputCommand()) return;

  if (interaction.commandName === 'test') {
    await interaction.reply('Hello boi!');
  }
});
client.login(config.BOT_TOKEN)

const rest = new REST({ version: '10' }).setToken(config.BOT_TOKEN); ^

TypeError: REST is not a constructor

I followed the instructions to create a bot. I run it and then this error occurs. I 've been looking everywhere for a solution


Solution

  • You should probably change the following:

    const { REST, Routes } = require('discord.js');
    

    with the following lines:

    const { REST } = require('@discordjs/rest');
    const { Routes } = require('discord-api-types/v10');
    

    This can been verified by checking this.