@@ -566,21 +566,7 @@ async def note(self, ctx, *, msg=''):
566566 async with ctx .typing ():
567567 await ctx .thread .note (ctx .message )
568568
569- @commands .command ()
570- @checks .has_permissions (PermissionLevel .SUPPORTER )
571- @checks .thread_only ()
572- async def edit (self , ctx , message_id : Optional [int ] = None ,
573- * , new_message ):
574- """Edit a message that was sent using the reply command.
575-
576- If no `message_id` is provided, the
577- last message sent by a mod will be edited.
578-
579- `[message_id]` the id of the message that you want to edit.
580- `new_message` is the new message that will be edited in.
581- """
582- thread = ctx .thread
583-
569+ async def find_linked_message (self , ctx , message_id ):
584570 linked_message_id = None
585571
586572 async for msg in ctx .channel .history ():
@@ -600,8 +586,31 @@ async def edit(self, ctx, message_id: Optional[int] = None,
600586 linked_message_id = str (url ).split ('/' )[- 1 ]
601587 break
602588
603- if not linked_message_id :
604- raise commands .UserInputError
589+ return linked_message_id
590+
591+ @commands .command ()
592+ @checks .has_permissions (PermissionLevel .SUPPORTER )
593+ @checks .thread_only ()
594+ async def edit (self , ctx , message_id : Optional [int ] = None ,
595+ * , new_message ):
596+ """Edit a message that was sent using the reply command.
597+
598+ If no `message_id` is provided, the
599+ last message sent by a mod will be edited.
600+
601+ `[message_id]` the id of the message that you want to edit.
602+ `new_message` is the new message that will be edited in.
603+ """
604+ thread = ctx .thread
605+
606+ linked_message_id = await self .find_linked_message (ctx , message_id )
607+
608+ if linked_message_id is None :
609+ return await ctx .send (embed = discord .Embed (
610+ title = 'Failed' ,
611+ description = 'Cannot find a message to edit.' ,
612+ color = discord .Color .red ()
613+ ))
605614
606615 await asyncio .gather (
607616 thread .edit_message (linked_message_id , new_message ),
@@ -801,6 +810,27 @@ async def unblock(self, ctx, *, user: User = None):
801810
802811 return await ctx .send (embed = embed )
803812
813+ @commands .command ()
814+ @checks .has_permissions (PermissionLevel .SUPPORTER )
815+ async def delete (self , ctx , message_id : int = None ):
816+ """
817+ Deletes the previous message, unless a message ID is provided, which in that case,
818+ delete the message with that message ID.
819+ """
820+ thread = ctx .thread
821+
822+ linked_message_id = await self .find_linked_message (ctx , message_id )
823+
824+ if linked_message_id is None :
825+ return await ctx .send (embed = discord .Embed (
826+ title = 'Failed' ,
827+ description = 'Cannot find a message to delete.' ,
828+ color = discord .Color .red ()
829+ ))
830+
831+ await thread .delete_message (linked_message_id )
832+ await ctx .message .add_reaction ('✅' )
833+
804834
805835def setup (bot ):
806836 bot .add_cog (Modmail (bot ))
0 commit comments