discord_get_audit_log
Fetch Discord server audit logs to track user actions, moderation events, and administrative changes for monitoring and security purposes.
Instructions
Fetch the guild audit log (who did what and when).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guild_id | Yes | ||
| limit | No | 1–100, default 25. | |
| action_type | No | Optional: filter by Discord action type ID. |
Implementation Reference
- src/tools/moderation.ts:27-39 (handler)The handler implementation for discord_get_audit_log, which fetches the audit log from the Discord client.
case "discord_get_audit_log": { const guild = await discord.guilds.fetch(validateId(args.guild_id, "guild_id")); const logs = await guild.fetchAuditLogs({ limit: Math.min(Number(args.limit ?? 25), 100), type: args.action_type as number | undefined, }); const result = logs.entries.map((entry) => ({ id: entry.id, action: entry.action, executor: entry.executor?.tag, target: entry.targetId, reason: entry.reason, createdAt: entry.createdAt.toISOString(), })); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } - src/tools/moderation.ts:5-18 (schema)The tool definition (schema) for discord_get_audit_log.
export const definitions = [ { name: "discord_get_audit_log", description: "Fetch the guild audit log (who did what and when).", inputSchema: { type: "object", properties: { guild_id: { type: "string" }, limit: { type: "number", description: "1–100, default 25." }, action_type: { type: "number", description: "Optional: filter by Discord action type ID." }, }, required: ["guild_id"], }, },