discord_audit_permissions
Generate a permission audit report to identify who can access each channel in a Discord guild, ensuring proper access control.
Instructions
Generate a full permission audit report for a guild: who can access what on every channel.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guild_id | Yes |
Implementation Reference
- src/tools/permissions.ts:143-171 (handler)The implementation of the 'discord_audit_permissions' tool handler, which fetches guild data and generates a permission overwrite report.
case "discord_audit_permissions": { const guild = await discord.guilds.fetch(validateId(args.guild_id, "guild_id")); await guild.channels.fetch(); await guild.roles.fetch(); const memberIdsNeeded = new Set<string>(); guild.channels.cache.forEach((ch) => { if (ch instanceof GuildChannel) { ch.permissionOverwrites.cache.forEach((ow) => { if (ow.type === 1) memberIdsNeeded.add(ow.id); }); } }); await Promise.all([...memberIdsNeeded].map((id) => guild.members.fetch(id).catch(() => null))); const report: Record<string, unknown>[] = []; guild.channels.cache .filter((c) => c instanceof GuildChannel) .forEach((ch) => { const gch = ch as GuildChannel; const overwrites = gch.permissionOverwrites.cache.map((ow) => { const isRole = ow.type === 0; const entity = isRole ? guild.roles.cache.get(ow.id)?.name ?? ow.id : guild.members.cache.get(ow.id)?.user.tag ?? ow.id; return { entity, type: isRole ? "role" : "member", allow: serializePermissions(ow.allow), deny: serializePermissions(ow.deny) }; }); if (overwrites.length > 0) report.push({ channel: gch.name, channelId: gch.id, overwrites }); }); return { content: [{ type: "text", text: JSON.stringify(report, null, 2) }] }; } - src/tools/permissions.ts:72-79 (schema)The schema definition for the 'discord_audit_permissions' tool.
name: "discord_audit_permissions", description: "Generate a full permission audit report for a guild: who can access what on every channel.", inputSchema: { type: "object", properties: { guild_id: { type: "string" } }, required: ["guild_id"], }, },