Skip to main content
Glama

delete_message

Remove a specific message from a Discord channel by providing server, channel, and message IDs. This tool helps manage content and maintain server guidelines.

Instructions

Delete a message from a channel

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
guildIdYesThe ID of the server (guild)
channelIdYesThe ID of the channel
messageIdYesThe ID of the message to delete
reasonNoReason for deletion

Implementation Reference

  • Handler function that performs the deletion: fetches guild, channel, message, checks channel type, deletes the message, handles errors, and returns result.
    async ({ guildId, channelId, messageId, reason }) => { 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); await message.delete(); return { messageId, message: 'Message deleted successfully' }; }); 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: guildId, channelId, messageId, optional reason.
    { 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 delete'), reason: z.string().optional().describe('Reason for deletion'), },
  • The server.tool call that registers the delete_message tool with name, description, input schema, and handler function.
    server.tool( 'delete_message', 'Delete a message from a channel', { 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 delete'), reason: z.string().optional().describe('Reason for deletion'), }, async ({ guildId, channelId, messageId, reason }) => { 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); await message.delete(); return { messageId, message: 'Message deleted successfully' }; }); 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:58-58 (registration)
    Top-level call to register all message tools including delete_message.
    registerMessageTools(server);

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