list_events
Retrieve all scheduled events in a Discord server with optional user count data to manage and track community activities.
Instructions
List all scheduled events in a server
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| withUserCount | No | Include user count (default true) |
Implementation Reference
- src/tools/event-tools.ts:16-46 (handler)Handler function that fetches scheduled events from the Discord guild using the Discord.js client, maps them to a structured format, handles errors with withErrorHandling, and returns JSON stringified content.async ({ guildId, withUserCount = true }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const events = await guild.scheduledEvents.fetch({ withUserCount }); return events.map((event) => ({ id: event.id, name: event.name, description: event.description, scheduledStartTime: event.scheduledStartAt?.toISOString(), scheduledEndTime: event.scheduledEndAt?.toISOString(), privacyLevel: GuildScheduledEventPrivacyLevel[event.privacyLevel], status: GuildScheduledEventStatus[event.status], entityType: GuildScheduledEventEntityType[event.entityType], entityId: event.entityId, channelId: event.channelId, creatorId: event.creatorId, userCount: event.userCount, location: event.entityMetadata?.location, image: event.coverImageURL(), url: event.url, })); }); 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/event-tools.ts:13-15 (schema)Input schema using Zod for validating guildId (required string) and optional withUserCount (boolean).guildId: z.string().describe('The ID of the server (guild)'), withUserCount: z.boolean().optional().describe('Include user count (default true)'), },
- src/tools/event-tools.ts:9-47 (registration)Registration of the 'list_events' tool on the MCP server using server.tool(), including name, description, input schema, and handler function.server.tool( 'list_events', 'List all scheduled events in a server', { guildId: z.string().describe('The ID of the server (guild)'), withUserCount: z.boolean().optional().describe('Include user count (default true)'), }, async ({ guildId, withUserCount = true }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const events = await guild.scheduledEvents.fetch({ withUserCount }); return events.map((event) => ({ id: event.id, name: event.name, description: event.description, scheduledStartTime: event.scheduledStartAt?.toISOString(), scheduledEndTime: event.scheduledEndAt?.toISOString(), privacyLevel: GuildScheduledEventPrivacyLevel[event.privacyLevel], status: GuildScheduledEventStatus[event.status], entityType: GuildScheduledEventEntityType[event.entityType], entityId: event.entityId, channelId: event.channelId, creatorId: event.creatorId, userCount: event.userCount, location: event.entityMetadata?.location, image: event.coverImageURL(), url: event.url, })); }); 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:62-62 (registration)Call to registerEventTools(server) which includes the list_events tool registration, within the createMcpServer function.registerEventTools(server);
- src/index.ts:20-20 (registration)Import of registerEventTools from event-tools.js to enable tool registration.import { registerEventTools } from './tools/event-tools.js';