Add reply functionality to discord_send tool

Co-authored-by: SootyOwl <7614538+SootyOwl@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-10-16 17:17:35 +00:00 committed by Sooty
parent e707f7d646
commit bc5a056ed0
3 changed files with 40 additions and 6 deletions

View File

@ -6,7 +6,8 @@ export const DiscordLoginSchema = z.object({
export const SendMessageSchema = z.object({ export const SendMessageSchema = z.object({
channelId: z.string(), channelId: z.string(),
message: z.string() message: z.string(),
replyToMessageId: z.string().optional()
}); });
export const GetForumChannelsSchema = z.object({ export const GetForumChannelsSchema = z.object({

View File

@ -52,12 +52,13 @@ export const toolList = [
}, },
{ {
name: "discord_send", name: "discord_send",
description: "Sends a message to a specified Discord text channel", description: "Sends a message to a specified Discord text channel. Optionally reply to another message by providing its message ID.",
inputSchema: { inputSchema: {
type: "object", type: "object",
properties: { properties: {
channelId: { type: "string" }, channelId: { type: "string" },
message: { type: "string" } message: { type: "string" },
replyToMessageId: { type: "string" }
}, },
required: ["channelId", "message"] required: ["channelId", "message"]
} }

View File

@ -3,7 +3,7 @@ import { ToolHandler } from './types.js';
import { handleDiscordError } from "../errorHandler.js"; import { handleDiscordError } from "../errorHandler.js";
export const sendMessageHandler: ToolHandler = async (args, { client }) => { export const sendMessageHandler: ToolHandler = async (args, { client }) => {
const { channelId, message } = SendMessageSchema.parse(args); const { channelId, message, replyToMessageId } = SendMessageSchema.parse(args);
try { try {
if (!client.isReady()) { if (!client.isReady()) {
@ -23,9 +23,41 @@ export const sendMessageHandler: ToolHandler = async (args, { client }) => {
// Ensure channel is text-based and can send messages // Ensure channel is text-based and can send messages
if ('send' in channel) { if ('send' in channel) {
await channel.send(message); // Build message options
const messageOptions: any = {};
// If replyToMessageId is provided, verify the message exists and add reply option
if (replyToMessageId) {
if ('messages' in channel) {
try {
// Verify the message exists
await channel.messages.fetch(replyToMessageId);
messageOptions.reply = { messageReference: replyToMessageId };
} catch (error) {
return {
content: [{ type: "text", text: `Cannot find message with ID: ${replyToMessageId} in channel ${channelId}` }],
isError: true
};
}
} else {
return {
content: [{ type: "text", text: `This channel type does not support message replies` }],
isError: true
};
}
}
// Set the message content
messageOptions.content = message;
await channel.send(messageOptions);
const responseText = replyToMessageId
? `Message successfully sent to channel ID: ${channelId} as a reply to message ID: ${replyToMessageId}`
: `Message successfully sent to channel ID: ${channelId}`;
return { return {
content: [{ type: "text", text: `Message successfully sent to channel ID: ${channelId}` }] content: [{ type: "text", text: responseText }]
}; };
} else { } else {
return { return {