edit_message
Modify existing bot messages in Discord servers by updating content with specific channel, message, and server identifiers.
Instructions
Edit a message sent by the bot
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guildId | Yes | The ID of the server (guild) | |
| channelId | Yes | The ID of the channel | |
| messageId | Yes | The ID of the message to edit | |
| content | Yes | The new message content |
Implementation Reference
- src/tools/message-tools.ts:125-149 (handler)The core handler function for the 'edit_message' tool. It uses Discord.js to fetch the guild, channel, and target message, validates the channel type, edits the message content, handles errors with withErrorHandling, and returns the updated message details or an error response.async ({ guildId, channelId, messageId, content }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channel = await guild.channels.fetch(channelId); if (!isMessageableChannel(channel)) { throw new Error('Channel does not support messages'); } const message = await channel.messages.fetch(messageId); const edited = await message.edit(content); return { messageId: edited.id, content: edited.content, editedAt: edited.editedAt?.toISOString(), }; }); 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/message-tools.ts:119-124 (schema)Zod schema defining the input parameters for the 'edit_message' tool: guildId, channelId, messageId, and new content.{ guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), messageId: z.string().describe('The ID of the message to edit'), content: z.string().describe('The new message content'), },
- src/tools/message-tools.ts:116-150 (registration)The server.tool registration call that defines, registers the 'edit_message' tool with MCP server, including name, description, input schema, and handler function.server.tool( 'edit_message', 'Edit a message sent by the bot', { guildId: z.string().describe('The ID of the server (guild)'), channelId: z.string().describe('The ID of the channel'), messageId: z.string().describe('The ID of the message to edit'), content: z.string().describe('The new message content'), }, async ({ guildId, channelId, messageId, content }) => { const result = await withErrorHandling(async () => { const client = await getDiscordClient(); const guild = await client.guilds.fetch(guildId); const channel = await guild.channels.fetch(channelId); if (!isMessageableChannel(channel)) { throw new Error('Channel does not support messages'); } const message = await channel.messages.fetch(messageId); const edited = await message.edit(content); return { messageId: edited.id, content: edited.content, editedAt: edited.editedAt?.toISOString(), }; }); 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/message-tools.ts:8-17 (helper)Helper function to validate if a channel supports sending messages, used in the edit_message handler and other message tools.function isMessageableChannel(channel: unknown): channel is MessageableChannel { if (!channel || typeof channel !== 'object') return false; const ch = channel as { type?: number }; return ch.type === ChannelType.GuildText || ch.type === ChannelType.GuildAnnouncement || ch.type === ChannelType.PublicThread || ch.type === ChannelType.PrivateThread || ch.type === ChannelType.AnnouncementThread; }
- src/index.ts:16-59 (registration)Higher-level registration: imports registerMessageTools and calls it on the MCP server instance, which in turn registers the edit_message tool.import { registerMessageTools } from './tools/message-tools.js'; import { registerEmojiTools } from './tools/emoji-tools.js'; import { registerWebhookTools } from './tools/webhook-tools.js'; import { registerInviteTools } from './tools/invite-tools.js'; import { registerEventTools } from './tools/event-tools.js'; import { registerThreadTools } from './tools/thread-tools.js'; import { registerAuditTools } from './tools/audit-tools.js'; import { registerDiscordPrompts } from './prompts/discord-prompts.js'; /** * Discord MCP Server * * This MCP server provides comprehensive tools for managing Discord servers. * It requires the DISCORD_BOT_TOKEN environment variable to be set. * * Available tool categories: * - Server Management: list_servers, get_server_info, modify_server * - Channel Management: list_channels, get_channel_info, create_channel, delete_channel, modify_channel * - Member Management: list_members, get_member_info, modify_member, kick_member, ban_member, unban_member, list_bans * - Role Management: list_roles, get_role_info, create_role, delete_role, modify_role, assign_role, remove_role * - Permission Management: get_channel_permissions, set_channel_permission, delete_channel_permission, list_permissions, sync_channel_permissions * - Message Management: send_message, get_messages, edit_message, delete_message, bulk_delete_messages, pin/unpin, reactions * - Emoji & Sticker Management: list_emojis, create_emoji, delete_emoji, modify_emoji, sticker operations * - Webhook Management: list_channel_webhooks, list_guild_webhooks, create_webhook, delete_webhook, modify_webhook, send_webhook_message * - Invite Management: list_invites, get_invite_info, create_invite, delete_invite * - Event Management: list_events, get_event_info, create_event, modify_event, delete_event, get_event_subscribers * - Thread Management: list_threads, create_thread, create_forum_post, modify_thread, delete_thread, join/leave, member management * - Audit & Moderation: get_audit_logs, list_audit_log_types, list_automod_rules, get_automod_rule, delete_automod_rule, toggle_automod_rule */ // Create a configured MCP server instance function createMcpServer(): McpServer { const server = new McpServer({ name: 'discord-mcp', version: '1.1.0', }); // Register all tool categories registerServerTools(server); registerChannelTools(server); registerMemberTools(server); registerRoleTools(server); registerPermissionTools(server); registerMessageTools(server);