Unable to catch the disalowed intent

I constantly fail to catch the missing intents. How can I catch this error?
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.MessageContent,
],
partials: [Partials.Channel],
});

client.on('ready', () => {
console.log(`Ready: ${client.user.tag}`);
});

client.on('warn', (msg) => {
console.warn(`Warn: ${msg}`);
});

client.on('error', (msg) => {
console.error(`Error: ${msg}`);
}); //

await client
.login(token)
.catch((error) => {
console.error('Error logging in:', error);
});
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.MessageContent,
],
partials: [Partials.Channel],
});

client.on('ready', () => {
console.log(`Ready: ${client.user.tag}`);
});

client.on('warn', (msg) => {
console.warn(`Warn: ${msg}`);
});

client.on('error', (msg) => {
console.error(`Error: ${msg}`);
}); //

await client
.login(token)
.catch((error) => {
console.error('Error logging in:', error);
});
17 Replies
d.js toolkit
d.js toolkit5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
d.js docs
d.js docs5mo ago
- Error [DisallowedIntents]: Privileged intent provided is not enabled or whitelisted. - Error: Used disallowed intents If you are using the GuildMembers, GuildPresences, or MessageContent intents, you need to enable them via Developer Portal > Your app > Bot > Privileged Gateway Intents
! 🎃 ᒪเ𝔫Ѷε𝓝𝓽ί𝔣 👽 !
yup I know but I want to catch the error actually it just block my code
! 🎃 ᒪเ𝔫Ѷε𝓝𝓽ί𝔣 👽 !
GitHub
Regression starting from v14.10.0: "disallowed intents" is not catc...
Which package is this bug report for? discord.js Issue description If you run client.login() specifying privileged intents (like GuildMembers) while the bot doesn't have permission for that, No...
monbrey
monbrey5mo ago
Perfect example of why attempting a global anti-crash is bad
! 🎃 ᒪเ𝔫Ѷε𝓝𝓽ί𝔣 👽 !
so no way to catch it ?
monbrey
monbrey5mo ago
Not currently
! 🎃 ᒪเ𝔫Ѷε𝓝𝓽ί𝔣 👽 !
ok I think I have a idea with child process than yup I did it
async function checkTokenAndIntents(token) {
return new Promise((resolve, reject) => {
const child = fork(path.join(__dirname, 'testLogin.js'));

child.on('message', (message) => {
if (message === 'OK') {
resolve(true);
}
});

child.on('exit', (code) => {
if (code !== 0) {
resolve(false);
}
});

child.send(token);
});
}
async function checkTokenAndIntents(token) {
return new Promise((resolve, reject) => {
const child = fork(path.join(__dirname, 'testLogin.js'));

child.on('message', (message) => {
if (message === 'OK') {
resolve(true);
}
});

child.on('exit', (code) => {
if (code !== 0) {
resolve(false);
}
});

child.send(token);
});
}
import { Client, GatewayIntentBits, Partials } from 'discord.js';

async function testLogin(token) {
try {
const client = new Client({
intents: [
GatewayIntentBits.AutoModerationConfiguration,
GatewayIntentBits.AutoModerationExecution,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildScheduledEvents,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
],
partials: [Partials.Channel],
});

await client.login(token);
client.destroy();
process.send('OK');
} catch (error) {
console.error('Login failed:', error);
process.exit(1);
}
}

process.on('message', (token) => {
testLogin(token);
});
import { Client, GatewayIntentBits, Partials } from 'discord.js';

async function testLogin(token) {
try {
const client = new Client({
intents: [
GatewayIntentBits.AutoModerationConfiguration,
GatewayIntentBits.AutoModerationExecution,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildScheduledEvents,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
],
partials: [Partials.Channel],
});

await client.login(token);
client.destroy();
process.send('OK');
} catch (error) {
console.error('Login failed:', error);
process.exit(1);
}
}

process.on('message', (token) => {
testLogin(token);
});
monbrey
monbrey5mo ago
Why exactly do you require this solution?
! 🎃 ᒪเ𝔫Ѷε𝓝𝓽ί𝔣 👽 !
custom bot for a saas, the other solution will be docker with dynamic nginx config
monbrey
monbrey5mo ago
So they'll be providing their own token, and you're building error handling around it being set up incorrectly?
monbrey
monbrey5mo ago
I'd probably simply refer them to setting it up according to documentation, but I guess that makes sense
! 🎃 ᒪเ𝔫Ѷε𝓝𝓽ί𝔣 👽 !
yup but I can't let 1 user kill a multi user process
monbrey
monbrey5mo ago
The bots are all running on a single process?
! 🎃 ᒪเ𝔫Ѷε𝓝𝓽ί𝔣 👽 !
yes you just made me realise I can multi process will see the docs
Want results from more Discord servers?
Add your server