discord_add_reaction
Add an emoji reaction to a specific Discord message using the channel ID, message ID, and emoji.
Instructions
Adds an emoji reaction to a specific Discord message
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channelId | Yes | ||
| messageId | Yes | ||
| emoji | Yes |
Implementation Reference
- src/tools/reactions.ts:11-61 (handler)The main handler function `addReactionHandler` that executes the tool logic: parses args with AddReactionSchema, checks Discord client readiness, fetches the channel, fetches the message, and calls `message.react(emoji)`. Returns success/error response.
export async function addReactionHandler( args: unknown, context: ToolContext ): Promise<ToolResponse> { const { channelId, messageId, emoji } = AddReactionSchema.parse(args); try { if (!context.client.isReady()) { return { content: [{ type: 'text', text: 'Discord client not logged in.' }], isError: true, }; } const channel = await context.client.channels.fetch(channelId); if (!(channel?.isTextBased() && 'messages' in channel)) { return { content: [ { type: 'text', text: `Cannot find text channel with ID: ${channelId}`, }, ], isError: true, }; } const message = await channel.messages.fetch(messageId); if (!message) { return { content: [ { type: 'text', text: `Cannot find message with ID: ${messageId}` }, ], isError: true, }; } // Add the reaction await message.react(emoji); return { content: [ { type: 'text', text: `Successfully added reaction ${emoji} to message ID: ${messageId}`, }, ], }; } catch (error) { return handleDiscordError(error); } } - src/schemas.ts:73-77 (schema)Zod schema `AddReactionSchema` defining input validation: channelId (string), messageId (string), emoji (string).
export const AddReactionSchema = z.object({ channelId: z.string(), messageId: z.string(), emoji: z.string(), }); - src/tool-list.ts:174-185 (registration)Tool registration entry in `toolList`: name 'discord_add_reaction', description, and inputSchema matching the Zod schema.
{ name: 'discord_add_reaction', description: 'Adds an emoji reaction to a specific Discord message', inputSchema: { type: 'object', properties: { channelId: { type: 'string' }, messageId: { type: 'string' }, emoji: { type: 'string' }, }, required: ['channelId', 'messageId', 'emoji'], }, - src/server.ts:161-164 (registration)Server-side registration: case 'discord_add_reaction' calls `addReactionHandler(args, this.toolContext)`.
case 'discord_add_reaction': this.logClientState('before discord_add_reaction handler'); toolResponse = await addReactionHandler(args, this.toolContext); return toolResponse; - src/tools/tools.ts:18-39 (helper)Re-export of `addReactionHandler` from `./reactions.js` in the tools barrel module.
export { addMultipleReactionsHandler, addReactionHandler, deleteMessageHandler, removeReactionHandler, } from './reactions.js'; export { sendMessageHandler } from './send-message.js'; export { ToolContext, ToolHandler, ToolResponse } from './types.js'; export { createWebhookHandler, deleteWebhookHandler, editWebhookHandler, sendWebhookMessageHandler, } from './webhooks.js'; import type { Client } from 'discord.js'; import type { ToolContext } from './types.js'; // Create tool context export function createToolContext(client: Client): ToolContext { return { client }; }