Update guilds route

This commit is contained in:
Isaac
2022-05-07 18:28:38 +01:00
parent ad9bd98933
commit c082552fae
2 changed files with 35 additions and 5 deletions

View File

@@ -1,9 +1,17 @@
module.exports.get = fastify => ({
handler: async (req, res) => {
const { client } = res.context.config;
const user = await client.users.fetch(req.user.payload.id);
console.log(req.user.payload.username, user?.tag);
res.send(client.guilds.cache);
const guilds = client.guilds.cache
.filter(async guild => {
const member = await guild.members.fetch(req.user.payload.id);
return member.permissions.has('MANAGE_GUILD');
})
.map(guild => ({
id: guild.id,
logo: guild.iconURL(),
name: guild.name,
}));
res.send(guilds);
},
onRequest: [fastify.authenticate],
});