Skip to main content
Glama

edit_message

Modify existing bot messages in Discord servers by providing new content, channel ID, and message ID to update communications.

Instructions

Edit a message sent by the bot

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
channelIdYesThe ID of the channel
messageIdYesThe ID of the message to edit
contentYesThe new message content

Implementation Reference

  • Registers the 'edit_message' MCP tool with input schema (guildId, channelId, messageId, content) and handler function that fetches the Discord channel and message, edits the message content, and returns the updated message details.
    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) }] }; } );
  • The async handler function for the edit_message tool, which uses Discord.js to edit a specified message and handles errors via withErrorHandling.
    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) }] }; }
  • Zod input schema defining parameters for the edit_message tool.
    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/index.ts:58-58 (registration)
    Calls registerMessageTools to register all message tools including edit_message on the MCP server instance.
    registerMessageTools(server);
  • Helper function used by edit_message handler to validate if the channel supports sending/editing messages.
    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; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/scarecr0w12/discord-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server