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 toolkitβ€’6mo 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 docsβ€’6mo 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
monbreyβ€’6mo ago
Perfect example of why attempting a global anti-crash is bad
monbrey
monbreyβ€’6mo 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
monbreyβ€’6mo ago
Why exactly do you require this solution?
! πŸŽƒ α’ͺเ𝔫ѢΡ𝓝𝓽ί𝔣 πŸ‘½ !
custom bot for a saas, the other solution will be docker with dynamic nginx config
monbrey
monbreyβ€’6mo ago
So they'll be providing their own token, and you're building error handling around it being set up incorrectly?
monbrey
monbreyβ€’6mo 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
monbreyβ€’6mo 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