@@ -15,8 +15,9 @@ def message_group():
1515@click .argument ("text" )
1616@click .option ("--embed-title" , default = None , help = "Embed title." )
1717@click .option ("--embed-desc" , default = None , help = "Embed description." )
18+ @click .option ("--file" , "files" , multiple = True , type = click .Path (exists = True ), help = "File to attach (repeatable)." )
1819@click .pass_context
19- def message_send (ctx , channel , text , embed_title , embed_desc ):
20+ def message_send (ctx , channel , text , embed_title , embed_desc , files ):
2021 """Send a message to a channel."""
2122
2223 def action (client ):
@@ -25,8 +26,14 @@ async def _action(client):
2526 embed = None
2627 if embed_title or embed_desc :
2728 embed = discord .Embed (title = embed_title , description = embed_desc )
28- msg = await ch .send (content = text , embed = embed )
29+ attachments = [discord .File (f ) for f in files ]
30+ kwargs = {"content" : text , "embed" : embed }
31+ if attachments :
32+ kwargs ["files" ] = attachments
33+ msg = await ch .send (** kwargs )
2934 data = {"id" : str (msg .id ), "channel" : ch .name , "content" : msg .content }
35+ if msg .attachments :
36+ data ["attachments" ] = [{"filename" : a .filename , "url" : a .url , "size" : a .size } for a in msg .attachments ]
3037 output (ctx , data , plain_text = f"Sent message { msg .id } to #{ ch .name } " )
3138 return _action (client )
3239
@@ -207,16 +214,23 @@ async def _action(client):
207214@click .argument ("channel" )
208215@click .argument ("message_id" )
209216@click .argument ("text" )
217+ @click .option ("--file" , "files" , multiple = True , type = click .Path (exists = True ), help = "File to attach (repeatable)." )
210218@click .pass_context
211- def message_reply (ctx , channel , message_id , text ):
219+ def message_reply (ctx , channel , message_id , text , files ):
212220 """Reply to a specific message."""
213221
214222 def action (client ):
215223 async def _action (client ):
216224 ch = resolve_channel (client , channel )
217225 original = await ch .fetch_message (int (message_id ))
218- msg = await original .reply (content = text )
226+ attachments = [discord .File (f ) for f in files ]
227+ kwargs = {"content" : text }
228+ if attachments :
229+ kwargs ["files" ] = attachments
230+ msg = await original .reply (** kwargs )
219231 data = {"id" : str (msg .id ), "channel" : ch .name , "content" : msg .content , "reply_to" : message_id }
232+ if msg .attachments :
233+ data ["attachments" ] = [{"filename" : a .filename , "url" : a .url , "size" : a .size } for a in msg .attachments ]
220234 output (ctx , data , plain_text = f"Replied to { message_id } in #{ ch .name } " )
221235 return _action (client )
222236
0 commit comments