add_reaction
Add an emoji reaction to a Discord message by specifying server, channel, message, and emoji identifiers.
Instructions
Add a reaction to a message
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 | |
| emoji | Yes | The emoji to react with (unicode or custom emoji ID) |
Implementation Reference
- src/tools/message-tools.ts:329-349 (handler)The handler function for the 'add_reaction' tool. Fetches the Discord guild, channel, and message, then adds the specified emoji reaction to the message using message.react(). Wraps in error handling and returns formatted response.async ({ guildId, channelId, messageId, emoji }) => { 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.react(emoji); return { messageId, emoji, message: 'Reaction added 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/tools/message-tools.ts:323-328 (schema)Input schema for the 'add_reaction' tool using Zod validation. Defines required string parameters: guildId, channelId, messageId, and emoji.{ 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'), emoji: z.string().describe('The emoji to react with (unicode or custom emoji ID)'), },
- src/tools/message-tools.ts:320-350 (registration)Direct registration of the 'add_reaction' tool using server.tool(), including name, description, input schema, and handler function within registerMessageTools.server.tool( 'add_reaction', 'Add a reaction to a message', { 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'), emoji: z.string().describe('The emoji to react with (unicode or custom emoji ID)'), }, async ({ guildId, channelId, messageId, emoji }) => { 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.react(emoji); return { messageId, emoji, message: 'Reaction added 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 registerMessageTools(server) in createMcpServer(), which registers the add_reaction tool among others.registerMessageTools(server);
- src/tools/message-tools.ts:9-17 (helper)Helper function used by the handler to validate if a channel supports messages (TextChannel, NewsChannel, ThreadChannel).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; }