list_automod_rules
Retrieve and display all auto-moderation rules configured for a Discord server to manage content filtering and moderation settings.
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 logic for the list_automod_rules tool. Fetches all auto-moderation rules from the specified 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 required guildId parameter.{ guildId: z.string().describe('The ID of the server (guild)'), },
- src/tools/audit-tools.ts:99-134 (registration)Registers the list_automod_rules tool on the MCP server within the registerAuditTools function.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:64-64 (registration)Higher-level registration call that invokes registerAuditTools to set up all audit tools including list_automod_rules.registerAuditTools(server);
- src/index.ts:22-22 (registration)Import of the registerAuditTools function used to register the audit tools.import { registerAuditTools } from './tools/audit-tools.js';