add_reaction
Add emoji reactions to Discord messages by specifying server, channel, message IDs and emoji. React to messages programmatically within Discord servers.
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:320-350 (registration)Registration and implementation of the 'add_reaction' tool. Defines the input schema using Zod and the handler function that fetches the Discord channel and message, validates the channel type, and adds the specified emoji reaction using message.react(emoji). Returns success/error response.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/tools/message-tools.ts:329-349 (handler)The core handler function for the add_reaction tool. It uses withErrorHandling to fetch the Discord guild, channel, and message, checks if the channel supports messages, adds the reaction with message.react(emoji), and formats the 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-327 (schema)Zod schema defining input parameters for the add_reaction tool: 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/index.ts:59-59 (registration)Top-level registration call that includes the add_reaction tool by invoking registerMessageTools on the MCP server instance.registerMessageTools(server);