list_automod_rules
Retrieve all auto-moderation rules configured in a Discord server to review content filtering settings and moderation policies.
Instructions
List all auto-moderation rules in a server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) |
Implementation Reference
- src/tools/audit-tools.ts:105-133 (handler)The core handler function that implements the list_automod_rules tool logic: fetches auto-moderation rules from Discord guild and serializes them to JSON.async ({ guildId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const rules = await guild.autoModerationRules.fetch(); return rules.map((rule) => ({ id: rule.id, name: rule.name, enabled: rule.enabled, eventType: rule.eventType, triggerType: rule.triggerType, triggerMetadata: rule.triggerMetadata, actions: rule.actions.map((action) => ({ type: action.type, metadata: action.metadata, })), exemptRoles: rule.exemptRoles.map((r) => ({ id: r.id, name: r.name })), exemptChannels: rule.exemptChannels.map((c) => ({ id: c.id, name: c.name })), creatorId: rule.creatorId, })); }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; }
- src/tools/audit-tools.ts:102-104 (schema)Zod input schema defining the guildId parameter for the tool.{ guildId: z.string().describe('The ID of the server (guild)'), },
- src/tools/audit-tools.ts:98-134 (registration)Registration of the list_automod_rules tool using server.tool(), including name, description, schema, and handler reference.// List auto-moderation rules server.tool( 'list_automod_rules', 'List all auto-moderation rules in a server', { guildId: z.string().describe('The ID of the server (guild)'), }, async ({ guildId }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const rules = await guild.autoModerationRules.fetch(); return rules.map((rule) => ({ id: rule.id, name: rule.name, enabled: rule.enabled, eventType: rule.eventType, triggerType: rule.triggerType, triggerMetadata: rule.triggerMetadata, actions: rule.actions.map((action) => ({ type: action.type, metadata: action.metadata, })), exemptRoles: rule.exemptRoles.map((r) => ({ id: r.id, name: r.name })), exemptChannels: rule.exemptChannels.map((c) => ({ id: c.id, name: c.name })), creatorId: rule.creatorId, })); }); if (!result.success) { return { content: [{ type: 'text', text: result.error }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } );
- src/index.ts:65-65 (registration)Top-level registration call to registerAuditTools which includes the list_automod_rules tool among audit tools.registerAuditTools(server);