Skip to content

Commit 02a496a

Browse files
authored
Fixed Problems when Putting the Callback in an Variable to edit it later
1 parent 0f6386f commit 02a496a

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

discord/abc.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"""
2828

2929
import abc
30+
import json
3031
import sys
3132
import copy
3233
import asyncio
@@ -1072,7 +1073,7 @@ async def send(self, content=None, *, tts=False, embed=None, embeds=None, compon
10721073
if hidden is not None:
10731074
embedlist = []
10741075
if embed:
1075-
embedlist.append(embed.to_dict())
1076+
embedlist.append(embed)
10761077
if embeds:
10771078
embedlist.extend([e.to_dict() for e in embeds])
10781079
embeds = embedlist
@@ -1095,7 +1096,7 @@ async def send(self, content=None, *, tts=False, embed=None, embeds=None, compon
10951096
content=content, tts=tts, embeds=embeds,
10961097
components=components,
10971098
nonce=nonce, message_reference=reference,
1098-
flags=64 if hidden else None,
1099+
flags=64 if hidden is True else None,
10991100
followup=followup)
11001101
else:
11011102
data = await state.http.send_files(channel.id, files=[file], allowed_mentions=allowed_mentions,
@@ -1121,8 +1122,8 @@ async def send(self, content=None, *, tts=False, embed=None, embeds=None, compon
11211122
content=content, tts=tts, embeds=embeds,
11221123
components=components,
11231124
nonce=nonce, message_reference=reference,
1124-
flags=64 if hidden else None,
1125-
followup=followup)
1125+
flags=64 if hidden is True else None,
1126+
followup=followup or deferred)
11261127
else:
11271128
data = await state.http.send_files(channel.id, files=files, content=content, tts=tts,
11281129
embeds=embeds, components=components, nonce=nonce,
@@ -1140,19 +1141,20 @@ async def send(self, content=None, *, tts=False, embed=None, embeds=None, compon
11401141
content=content, tts=tts, embeds=embeds,
11411142
components=components,
11421143
nonce=nonce, message_reference=reference,
1143-
flags=64 if hidden else None,
1144+
flags=64 if hidden is True else None,
11441145
followup=followup)
11451146
else:
11461147
data = await state.http.send_message(channel.id, content, tts=tts, embed=embed, components=components,
11471148
nonce=nonce, allowed_mentions=allowed_mentions,
11481149
message_reference=reference)
1149-
1150-
if not hidden is True and isinstance(data, dict):
1150+
if not hidden is True:
1151+
if not isinstance(data, dict) and not hidden is None:
1152+
"""Thanks Discord that they dont return the message when we send the interaction callback"""
1153+
data = await state.http.get_original_interaction_response(application_id=application_id, interaction_token=interaction_token)
11511154
ret = state.create_message(channel=channel, data=data)
1152-
if delete_after is not None and hidden is None:
1155+
if (delete_after is not None) and (not hidden is True):
11531156
await ret.delete(delay=delete_after)
11541157
return ret
1155-
return None
11561158

11571159
async def trigger_typing(self):
11581160
"""|coro|

discord/components.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@
3838

3939

4040
class ButtonStyle:
41+
4142
"""
4243
:class:`Button`
4344
Represents the Style for an :class:`discord.Button`
4445
4546
.. note ::
4647
For more information about the Button-Styles visit the `Discord-API Documentation <https://discord.com/developers/docs/interactions/message-components#buttons-button-styles>`_.
48+
4749
"""
4850

4951
def __repr__(self):
@@ -59,11 +61,13 @@ def __repr__(self):
5961

6062

6163
class ButtonColor:
64+
6265
"""
6366
:class:`ButtonColor`
6467
6568
.. note ::
6669
This is just an Aliase to :class:`ButtonStyle`
70+
6771
"""
6872
blurple = ButtonStyle.Primary
6973
grey = ButtonStyle.Secondary

discord/http.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def edit_interaction_response(self, use_webhook, interaction_id, token, applicat
452452
if not deferred:
453453
fields = {'data': fields}
454454
fields['type'] = 7
455-
r = Route("POST", f'/webhooks/{application_id}/{token}/callback' if use_webhook is True else f"/interactions/{interaction_id}/{token}/callback")
455+
r = Route('POST', f'/webhooks/{application_id}/{token}/callback' if use_webhook is True else f"/interactions/{interaction_id}/{token}/callback")
456456
else:
457457
r = Route('PATCH', f'/webhooks/{application_id}/{token}/messages/@original')
458458
return self.request(r, json=fields)
@@ -485,13 +485,12 @@ def send_interaction_response(self, use_webhook, interaction_id, token, applicat
485485
payload['message_reference'] = message_reference
486486
if flags:
487487
payload['flags'] = flags
488-
if not deferred is True:
488+
if not deferred and not followup:
489489
payload = {'data': payload}
490490
payload['type'] = 4
491-
r = Route("POST", f'/webhooks/{application_id}/{token}/callback' if use_webhook is True else f"/interactions/{interaction_id}/{token}/callback")
492-
elif followup is True:
491+
r = Route('POST', f'/webhooks/{application_id}/{token}/callback' if use_webhook is True else f"/interactions/{interaction_id}/{token}/callback")
492+
else:
493493
r = Route('POST', f'/webhooks/{application_id}/{token}')
494-
495494
if files is not None:
496495
form.append({'name': 'payload_json', 'value': utils.to_json(payload)})
497496
if len(files) == 1:
@@ -515,6 +514,10 @@ def send_interaction_response(self, use_webhook, interaction_id, token, applicat
515514
else:
516515
return self.request(r, json=payload)
517516

517+
def get_original_interaction_response(self, interaction_token, application_id):
518+
r = Route('GET', f'/webhooks/{application_id}/{interaction_token}/messages/@original')
519+
return self.request(r)
520+
518521
def add_reaction(self, channel_id, message_id, emoji):
519522
r = Route('PUT', '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me',
520523
channel_id=channel_id, message_id=message_id, emoji=emoji)

discord/interactions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ async def respond(self, content=None, *, tts=False, embed=None, embeds=None, com
104104
msg = await self.channel.send(content, tts=tts, embed=embed, embeds=embeds, components=components, file=file,
105105
files=files, delete_after=delete_after, nonce=nonce,allowed_mentions=allowed_mentions,
106106
reference=reference, mention_author=mention_author, hidden=hidden,
107-
__is_interaction_responce=True, __deferred=self._deferred or self._deferred_hidden, __use_webhook=False,
107+
__is_interaction_responce=True, __deferred=self._deferred, __use_webhook=False,
108108
__interaction_id=self.__interaction_id, __interaction_token=self.__token,
109-
__application_id=self.__application_id, followup=True if self._deferred or self._deferred_hidden else False)
109+
__application_id=self.__application_id, followup=True if self.callback_message else False)
110110

111-
self._deffered = True
112111
if hidden is True:
113112
self._deferred_hidden = True
113+
self._deffered = True
114114
if not self.callback_message:
115115
self.callback_message = msg if msg else EphemeralMessage()
116-
return msg if msg else self.callback_message
116+
return msg
117117

118118
@property
119119
def author(self) -> typing.Union[Member, User]:

0 commit comments

Comments
 (0)