Skip to content

Commit 9a7a9d7

Browse files
authored
Merge pull request #17 from SootyOwl/copilot/add-reply-functionality
Add reply functionality
2 parents 306f6ab + bc5a056 commit 9a7a9d7

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

src/schemas.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export const DiscordLoginSchema = z.object({
66

77
export const SendMessageSchema = z.object({
88
channelId: z.string(),
9-
message: z.string()
9+
message: z.string(),
10+
replyToMessageId: z.string().optional()
1011
});
1112

1213
export const GetForumChannelsSchema = z.object({

src/toolList.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ export const toolList = [
5252
},
5353
{
5454
name: "discord_send",
55-
description: "Sends a message to a specified Discord text channel",
55+
description: "Sends a message to a specified Discord text channel. Optionally reply to another message by providing its message ID.",
5656
inputSchema: {
5757
type: "object",
5858
properties: {
5959
channelId: { type: "string" },
60-
message: { type: "string" }
60+
message: { type: "string" },
61+
replyToMessageId: { type: "string" }
6162
},
6263
required: ["channelId", "message"]
6364
}

src/tools/send-message.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ToolHandler } from './types.js';
33
import { handleDiscordError } from "../errorHandler.js";
44

55
export const sendMessageHandler: ToolHandler = async (args, { client }) => {
6-
const { channelId, message } = SendMessageSchema.parse(args);
6+
const { channelId, message, replyToMessageId } = SendMessageSchema.parse(args);
77

88
try {
99
if (!client.isReady()) {
@@ -23,9 +23,41 @@ export const sendMessageHandler: ToolHandler = async (args, { client }) => {
2323

2424
// Ensure channel is text-based and can send messages
2525
if ('send' in channel) {
26-
await channel.send(message);
26+
// Build message options
27+
const messageOptions: any = {};
28+
29+
// If replyToMessageId is provided, verify the message exists and add reply option
30+
if (replyToMessageId) {
31+
if ('messages' in channel) {
32+
try {
33+
// Verify the message exists
34+
await channel.messages.fetch(replyToMessageId);
35+
messageOptions.reply = { messageReference: replyToMessageId };
36+
} catch (error) {
37+
return {
38+
content: [{ type: "text", text: `Cannot find message with ID: ${replyToMessageId} in channel ${channelId}` }],
39+
isError: true
40+
};
41+
}
42+
} else {
43+
return {
44+
content: [{ type: "text", text: `This channel type does not support message replies` }],
45+
isError: true
46+
};
47+
}
48+
}
49+
50+
// Set the message content
51+
messageOptions.content = message;
52+
53+
await channel.send(messageOptions);
54+
55+
const responseText = replyToMessageId
56+
? `Message successfully sent to channel ID: ${channelId} as a reply to message ID: ${replyToMessageId}`
57+
: `Message successfully sent to channel ID: ${channelId}`;
58+
2759
return {
28-
content: [{ type: "text", text: `Message successfully sent to channel ID: ${channelId}` }]
60+
content: [{ type: "text", text: responseText }]
2961
};
3062
} else {
3163
return {

0 commit comments

Comments
 (0)