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 toolkit2mo 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!
Linventif
Linventif2mo ago
error:
No description
d.js docs
d.js docs2mo 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
Linventif
Linventif2mo ago
yup I know but I want to catch the error actually it just block my code
Linventif
Linventif2mo ago
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
monbrey2mo ago
Perfect example of why attempting a global anti-crash is bad
Linventif
Linventif2mo ago
so no way to catch it ?
monbrey
monbrey2mo ago
Not currently
Linventif
Linventif2mo ago
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
monbrey2mo ago
Why exactly do you require this solution?
Linventif
Linventif2mo ago
custom bot for a saas, the other solution will be docker with dynamic nginx config
monbrey
monbrey2mo ago
So they'll be providing their own token, and you're building error handling around it being set up incorrectly?
Linventif
Linventif2mo ago
👍
monbrey
monbrey2mo ago
I'd probably simply refer them to setting it up according to documentation, but I guess that makes sense
Linventif
Linventif2mo ago
yup but I can't let 1 user kill a multi user process
Want results from more Discord servers?
Add your server