Checking user permissions on guilds

app.get('/dashboard', ensureAuthenticated, async(req, res) => {
if (client && client.user) {
try {

const guilds = await Promise.all(
client.guilds.cache.map(async(guild) => {
try {
const member = await guild.members.fetch(req.user.discordId);
return {
id: guild.id,
name: guild.name,
hasAdmin: member.permissions.has(PermissionsBitField.Flags.Administrator),
hasBot: guild.members.cache.has(client.user.id)
};
} catch (error) {
console.error(`Failed to fetch member for guild ${guild.name}:`, error);
return null;
}
})
);

console.log('Fetched guilds:', guilds); // Returns just 1 guild in console

const userGuilds = guilds.filter(guild => guild && guild.hasAdmin && guild.hasBot);

res.render('dashboard', {
botData: { username: client.user.username },
user: req.user,
servers: userGuilds
});
} catch (error) {
console.error('Failed to fetch guilds:', error);
res.redirect('/dashboard?error=404');
}
} else {
res.redirect('/auth/discord');
}
});
app.get('/dashboard', ensureAuthenticated, async(req, res) => {
if (client && client.user) {
try {

const guilds = await Promise.all(
client.guilds.cache.map(async(guild) => {
try {
const member = await guild.members.fetch(req.user.discordId);
return {
id: guild.id,
name: guild.name,
hasAdmin: member.permissions.has(PermissionsBitField.Flags.Administrator),
hasBot: guild.members.cache.has(client.user.id)
};
} catch (error) {
console.error(`Failed to fetch member for guild ${guild.name}:`, error);
return null;
}
})
);

console.log('Fetched guilds:', guilds); // Returns just 1 guild in console

const userGuilds = guilds.filter(guild => guild && guild.hasAdmin && guild.hasBot);

res.render('dashboard', {
botData: { username: client.user.username },
user: req.user,
servers: userGuilds
});
} catch (error) {
console.error('Failed to fetch guilds:', error);
res.redirect('/dashboard?error=404');
}
} else {
res.redirect('/auth/discord');
}
});
In console i recieve 1 guild only Filtered user guilds: [ { id: '1256707124994772993', name: 'playground', hasAdmin: true, hasBot: true } ] And on page it shows only 1 guild(Note that i have 2 servers where i am owner)
No description
1 Reply
d.js toolkit
d.js toolkit4mo 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!
Want results from more Discord servers?
Add your server