22import discord
33from discord .ext import commands
44from . import http
5+ from . import error
56
67
78class SlashContext :
@@ -13,6 +14,8 @@ class SlashContext:
1314 :ivar interaction_id: Interaction ID of the command message.
1415 :ivar command_id: ID of the command.
1516 :ivar _http: :class:`.http.SlashCommandRequest` of the client.
17+ :ivar _discord: :class:`discord.ext.commands.Bot`
18+ :ivar sent: Whether you sent the initial response.
1619 :ivar guild: :class:`discord.Guild` instance of the command message.
1720 :ivar author: :class:`discord.Member` instance representing author of the command message.
1821 :ivar channel: :class:`discord.TextChannel` instance representing channel of the command message.
@@ -26,6 +29,8 @@ def __init__(self,
2629 self .interaction_id = _json ["id" ]
2730 self .command_id = _json ["data" ]["id" ]
2831 self ._http = _http
32+ self ._discord = _discord
33+ self .sent = False
2934 self .guild : discord .Guild = _discord .get_guild (int (_json ["guild_id" ]))
3035 self .author : discord .Member = self .guild .get_member (int (_json ["member" ]["user" ]["id" ])) if self .guild else None
3136 self .channel = self .guild .get_channel (int (_json ["channel_id" ])) if self .guild else None
@@ -46,10 +51,10 @@ async def send(self,
4651 :type embeds: List[discord.Embed]
4752 :param tts: Whether to speak message using tts. Default ``False``.
4853 :type tts: bool
49- :return: `None`
54+ :return: `` None` `
5055 """
5156 if embeds and len (embeds ) > 10 :
52- raise
57+ raise error . IncorrectFormat ( "Embed must be 10 or fewer." )
5358 base = {
5459 "type" : send_type ,
5560 "data" : {
@@ -59,7 +64,52 @@ async def send(self,
5964 "allowed_mentions" : []
6065 }
6166 }
62- await self ._http .post (base , self .interaction_id , self .__token )
67+ initial = True if not self .sent else False
68+ resp = await self ._http .post (base , self ._discord .user .id , self .interaction_id , self .__token , initial )
69+ self .sent = True
70+ return resp
71+
72+ async def edit (self ,
73+ message_id : typing .Union [int , str ] = "@original" ,
74+ send_type : int = 4 ,
75+ text : str = "" ,
76+ embeds : typing .List [discord .Embed ] = None ,
77+ tts : bool = False ):
78+ """
79+ Edits response of the slash command.
80+
81+ :param message_id: Response message ID. Default initial message.
82+ :param send_type: Type of the response. Refer Discord API DOCS for more info about types. Default ``4``.
83+ :type send_type: int
84+ :param text: Text of the response. Can be ``None``.
85+ :type text: str
86+ :param embeds: Embeds of the response. Maximum 10, can be empty.
87+ :type embeds: List[discord.Embed]
88+ :param tts: Whether to speak message using tts. Default ``False``.
89+ :type tts: bool
90+ :return: ``None``
91+ """
92+ if embeds and len (embeds ) > 10 :
93+ raise error .IncorrectFormat ("Embed must be 10 or fewer." )
94+ base = {
95+ "type" : send_type ,
96+ "data" : {
97+ "tts" : tts ,
98+ "content" : text ,
99+ "embeds" : [x .to_dict () for x in embeds ] if embeds else [],
100+ "allowed_mentions" : []
101+ }
102+ }
103+ await self ._http .edit (base , self ._discord .user .id , self .__token , message_id )
104+
105+ async def delete (self , message_id : typing .Union [int , str ] = "@original" ):
106+ """
107+ Deletes response of the slash command.
108+
109+ :param message_id: Response message ID. Default initial message.
110+ :return: ``None``
111+ """
112+ await self ._http .delete (self ._discord .user .id , self .__token , message_id )
63113
64114
65115"""
0 commit comments