Skip to content

Commit 9ac7133

Browse files
authored
Issue with using RawReactionActionEven.deffer and using RawReactionActionEvent.edit has been fixed
1 parent 2785543 commit 9ac7133

File tree

5 files changed

+35
-33
lines changed

5 files changed

+35
-33
lines changed

discord/abc.py

-1
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,6 @@ async def send(self, content=None, *, tts=False, embed=None, components=None, fi
10321032
elif isinstance(component, ActionRow):
10331033
components_list.extend(component.sendable())
10341034
components = components_list
1035-
print(component)
10361035

10371036

10381037
if allowed_mentions is not None:

discord/errors.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,13 @@ class EmptyActionRow(DiscordException):
230230
You could supress this Error by setting :attr:`force` in the __init__ of the :class:`discord.ActionRow` to :bool:`True`
231231
"""
232232
def __init__(self):
233-
msg = "The Discord-API alows you to send an empty ActionRow but wy should you do that? You will not see anything apearing in Discord.\n" \
234-
"Note: this Error could be supressed by adding `force=True` to the Innit of the ActionRow"
233+
msg = 'The Discord-API alows you to send an empty ActionRow but wy should you do that?' \
234+
'You will not see anything apearing in Discord.\n' \
235+
'Note: this Error could be supressed by adding `force=True` to the Innit of the ActionRow'
236+
super().__init__(msg)
237+
238+
class UnknowInteraction(DiscordException):
239+
def __init__(self, interaction_id: int):
240+
msg = f'You have already replied to this interaction ({interaction_id})' \
241+
f' and/or 15 minutes have passed since the interaction, which is why Discord has deleted the interaction.'
235242
super().__init__(msg)

discord/http.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -447,18 +447,18 @@ def edit_message(self, channel_id, message_id, **fields):
447447
return self.request(r, json=fields)
448448

449449
def post_initial_response(self, use_webhook, _resp, interaction_id, token, application_id):
450-
r_url = f"/webhooks/{application_id}/{token}" if use_webhook is True else f"/interactions/{interaction_id}/{token}/callback"
450+
r_url = f"/webhooks/{application_id}/{token}/callback" if use_webhook is True else f"/interactions/{interaction_id}/{token}/callback"
451451
r = Route("POST", r_url, self.V8BASE)
452-
return self.request(r, json=_resp )
452+
return self.request(r, json=_resp)
453453

454-
def edit_interaction_response(self, use_webhook, interaction_id, token, application_id, deffered, fields):
455-
print(deffered)
454+
def edit_interaction_response(self, use_webhook, interaction_id, token, application_id, deffered, **fields):
456455
if not deffered:
457-
fields['type'] = 7
458-
r = Route("POST", f"/webhooks/{application_id}/{token}" if use_webhook is True else f"/interactions/{interaction_id}/{token}/callback", self.V8BASE)
456+
base = {'data': fields}
457+
base['type'] = 7
458+
r = Route("POST", f'/webhooks/{application_id}/{token}/callback' if use_webhook is True else f"/interactions/{interaction_id}/{token}/callback", self.V8BASE)
459459
else:
460-
r = Route('PATCH', f"/webhooks/{application_id}/{token}/messages/@original" if use_webhook is True else f"/interactions/{application_id}/{token}/messages/@original", self.V8BASE)
461-
print(fields)
460+
base = fields
461+
r = Route('PATCH', f'/webhooks/{application_id}/{token}/messages/@original', self.V8BASE)
462462
return self.request(r, json=fields)
463463

464464
def add_reaction(self, channel_id, message_id, emoji):

discord/message.py

+15-14
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ def _handle_embeds(self, value):
713713
self.embeds = [Embed.from_dict(data) for data in value]
714714

715715
def _handle_components(self, value):
716-
self.components = [DecodeMessageComponents for data in value]
716+
self.components = [ActionRow.from_dict(data) for data in value]
717717

718718
def _handle_nonce(self, value):
719719
self.nonce = value
@@ -1153,29 +1153,29 @@ async def edit(self, **fields):
11531153
interaction_id = fields.pop('__interaction_id', None)
11541154
interaction_token = fields.pop('__interaction_token', None)
11551155
application_id = fields.pop('__application_id', None)
1156-
payload = {'data': fields}
1157-
if not deffered:
1158-
payload['type'] = 7
1159-
if payload:
1156+
if fields:
11601157
try:
11611158
data = await self._state.http.edit_interaction_response(use_webhook=use_webhook,
11621159
interaction_id=interaction_id,
11631160
token=interaction_token,
11641161
application_id=application_id,
1165-
deffered=deffered,
1166-
fields=payload)
1167-
except Exception as exc:
1168-
print (exc)
1162+
deffered=deffered,**fields)
1163+
except NotFound:
1164+
is_interaction_responce = None
11691165
raise UnknowInteraction(application_id)
11701166
else:
1171-
self._update(dict(data))
1167+
[self.__setattr__(k, v) for k, v in fields.items()]
11721168

11731169
elif is_interaction_responce is None:
11741170
payload = await self._state.http.edit_message(self.channel.id, self.id, **fields)
11751171
self._update(payload)
11761172
if delete_after is not None:
11771173
await self.delete(delay=delete_after)
11781174

1175+
@property
1176+
def dict(self):
1177+
return {s: self.__getattribute__(s) for s in self.__slots__ if not s.startswith('_')}
1178+
11791179
async def publish(self):
11801180
"""|coro|
11811181
@@ -1686,17 +1686,18 @@ async def edit(self, **fields):
16861686
interaction_id = fields.pop('__interaction_id', None)
16871687
interaction_token = fields.pop('__interaction_token', None)
16881688
application_id = fields.pop('__application_id', None)
1689-
payload = {'data': fields}
1690-
if payload:
1689+
if fields:
16911690
try:
16921691
data = await self._state.http.edit_interaction_response(use_webhook=use_webhook,
16931692
interaction_id=interaction_id,
16941693
token=interaction_token,
16951694
application_id=application_id,
1696-
deffered=deffered,
1697-
fields=payload)
1695+
deffered=deffered, **fields)
16981696
except NotFound:
1697+
is_interaction_responce = None
16991698
raise UnknowInteraction(application_id)
1699+
else:
1700+
[self.__setattr__(k, v) for k, v in fields.items()]
17001701

17011702
elif is_interaction_responce is None:
17021703
payload = await self._state.http.edit_message(self.channel.id, self.id, **fields)

discord/raw_models.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def __init__(self, data, http=None):
266266
self.message: Message = None
267267
self._deferred = False
268268

269-
async def defer(self):
269+
async def defer(self, ):
270270
"""
271271
'Defers' the response, showing a loading state to the user
272272
"""
@@ -286,13 +286,8 @@ async def edit(self, **fields):
286286
"""
287287
if not self.message:
288288
self.message: Message = await self.channel.fetch_message(self._message_id)
289-
290-
try:
291-
await self.message.edit(__is_interaction_responce=True, __deffered=self.deffered, __use_webhook=False, __interaction_id=self.__interaction_id, __interaction_token=self.__token, __application_id=self.__application_id, **fields)
292-
except NotFound:
293-
pass
294-
else:
295-
self._deferred = True
289+
await self.message.edit(__is_interaction_responce=True, __deffered=self.deffered, __use_webhook=False, __interaction_id=self.__interaction_id, __interaction_token=self.__token, __application_id=self.__application_id, **fields)
290+
self._deferred = True
296291

297292
@property
298293
def deffered(self):

0 commit comments

Comments
 (0)