Merge pull request #17 from SootyOwl/copilot/add-reply-functionality

Add reply functionality
This commit is contained in:
Barry Yip 2025-10-20 15:45:22 +08:00 committed by GitHub
commit 9a7a9d7fea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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({
channelId: z.string(),
message: z.string()
message: z.string(),
replyToMessageId: z.string().optional()
});
export const GetForumChannelsSchema = z.object({

View File

@ -52,12 +52,13 @@ export const toolList = [
},
{
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: {
type: "object",
properties: {
channelId: { type: "string" },
message: { type: "string" }
message: { type: "string" },
replyToMessageId: { type: "string" }
},
required: ["channelId", "message"]
}

View File

@ -3,7 +3,7 @@ import { ToolHandler } from './types.js';
import { handleDiscordError } from "../errorHandler.js";
export const sendMessageHandler: ToolHandler = async (args, { client }) => {
const { channelId, message } = SendMessageSchema.parse(args);
const { channelId, message, replyToMessageId } = SendMessageSchema.parse(args);
try {
if (!client.isReady()) {
@ -23,9 +23,41 @@ export const sendMessageHandler: ToolHandler = async (args, { client }) => {
// Ensure channel is text-based and can send messages
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 {
content: [{ type: "text", text: `Message successfully sent to channel ID: ${channelId}` }]
content: [{ type: "text", text: responseText }]
};
} else {
return {