@@ -3,7 +3,7 @@ import { ToolHandler } from './types.js';
33import { handleDiscordError } from "../errorHandler.js" ;
44
55export 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