Discord Bot - Cannot access FLAGS from Intents

Viewed 939

I started coding personal bot. I'm getting an error

TypeError: Cannot read properties of undefined (reading 'FLAGS')

I'm assuming it can't access FLAGS. I don't understand why because I have installed the latest node and discord.js. I allowed all premission for 'Privileged Gateway Intents' for my Bot on my personal account on Discord Developer Portal. I followed this tutorial: https://www.youtube.com/watch?v=Qc9uPgGmQ7I

This is my code so far:

require("dotenv").config();
const { Client, Intents } = require("discord.js")
const client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MESSAGES
  ]
});

client.on("ready", () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on("interactionCreate", async interaction => {
  if (!interaction.isCommand()) return;

  if (interaction.commandName === "ping") {
    await interaction.reply("Pong!");
  }
});

client.login(process.env.SPELL_BOT_TOKEN)
2 Answers

It means you are using Discord.js v11 or older, where intents weren't there so to update it to v12 or newer you can:

  • Reinstall the module with npm uninstall discord.js and npm install discord.js.
  • Update it to the latest version with npm install discord.js@dev or a specific one with npm install discord.js@13.3.1.
  • Edit the version of the module in your package.json file.

the first mistake I see is that you have to pass object to Client class, you did new Client(intents: [...]}). should be like new Client({ intents: [...] })

Related