I am having an issue getting my intents to import from discord.js.
import { Client, Intents } from 'discord.js'
const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES] });
const token = 'mytoken'
client.on('ready', () => {
console.log('bot logged in')
})
client.login(token)
When I run npm index.js I get this error: Intent error
Could my installation of the discord.js package be corrupt or maybe didnt install all the way/properly? This is my first time messing with the discord api so im not too familiar with it all yet. Reading documentation and still confused as to why mine wont import properly.
CodePudding user response:
Apparently in v14 of Discord.js Intents was changed to GatewayIntentBits: https://discordjs.guide/additional-info/changes-in-v14.html#enum-values
// import Discord from 'discord.js'
import { Client, GatewayIntentBits } from 'discord.js'
// const Discord = require("discord.js");
// const { Client, GatewayIntentBits } = require("discord.js")
const client = new Client({
intents: [
GatewayIntentBits.GUILDS,
GatewayIntentBits.GUILD_MESSAGES
]
});
const token = 'mytoken'
client.on('ready', () => {
console.log('bot logged in')
})
client.login(token)
CodePudding user response:
I think you missed to import Discord on the first place. You are almost there. Just try this out,
import { Client, GatewayIntentBits } from 'discord.js';
const client = new Client({ intents: [GatewayIntentBits.Flags.Guilds, GatewayIntentBits.Flags.GuildMessages] });
const token = 'mytoken'
client.on('ready', () => {
console.log('bot logged in')
})
client.login(token)