Skip to content

Commit a760950

Browse files
authored
Add files via upload
1 parent 7e7cec0 commit a760950

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

discord/components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __init__(self, **kwargs):
9595
'The maximum length of Button-custom_id\'s are 100; your one is %s long. (%s Characters to long)' % (len(self.custom_id), len(self.custom_id) - 100))
9696
if self._custom_id and self.url:
9797
raise URLAndCustomIDNotAlowed(self.custom_id)
98-
self._label: str = kwargs.get('label', kwargs.get('name', 'I\'m an Button'))
98+
self._label: str = kwargs.get('label', kwargs.get('name', ''))
9999
if self._label and len(self._label) > 80:
100100
raise InvalidArgument(f'The maximum length of Button-Labels\'s are 80; your one is {len(self.label)} long. ({len(self.label) - 100} Characters to long)')
101101
self._emoji = kwargs.get('emoji', None)

discord/errors.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2424
DEALINGS IN THE SOFTWARE.
2525
"""
26+
import sys
27+
2628

2729
class DiscordException(Exception):
2830
"""Base exception class for discord.py
@@ -31,6 +33,13 @@ class DiscordException(Exception):
3133
"""
3234
pass
3335

36+
class DiscordWarning(Warning):
37+
"""Base warning class for discord.py
38+
39+
Ideally speaking, this could be caught to handle any warnings thrown from this library.
40+
"""
41+
pass
42+
3443
class ClientException(DiscordException):
3544
"""Exception that's thrown when an operation in the :class:`Client` fails.
3645
@@ -235,7 +244,7 @@ def __init__(self):
235244
'Note: this Error could be supressed by adding `force=True` to the Innit of the ActionRow'
236245
super().__init__(msg)
237246

238-
class UnknowInteraction(DiscordException):
247+
class UnknowInteraction(DiscordWarning):
239248
def __init__(self, interaction_id: int):
240249
msg = f'You have already replied to this interaction ({interaction_id})' \
241250
f' and/or 15 minutes have passed since the interaction, which is why Discord has deleted the interaction.'

discord/message.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,10 +1159,9 @@ async def edit(self, **fields):
11591159
interaction_id=interaction_id,
11601160
token=interaction_token,
11611161
application_id=application_id,
1162-
deffered=deffered,**fields)
1162+
deffered=deffered, **fields)
11631163
except NotFound:
11641164
is_interaction_responce = None
1165-
raise UnknowInteraction(application_id)
11661165
else:
11671166
[self.__setattr__(k, v) for k, v in fields.items()]
11681167

@@ -1695,7 +1694,6 @@ async def edit(self, **fields):
16951694
deffered=deffered, **fields)
16961695
except NotFound:
16971696
is_interaction_responce = None
1698-
raise UnknowInteraction(application_id)
16991697
else:
17001698
[self.__setattr__(k, v) for k, v in fields.items()]
17011699

discord/raw_models.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2626
DEALINGS IN THE SOFTWARE.
2727
"""
28+
import sys
2829
import typing
2930
from .member import Member
31+
from .user import User
3032
from .message import Message
31-
from .errors import NotFound
33+
from .errors import NotFound, UnknowInteraction
3234

3335

3436
class _RawReprMixin:
@@ -253,15 +255,15 @@ def __init__(self, data, http=None):
253255
self._message_id = data.get('message').get('id', None)
254256
self._data = data.get('data', None)
255257
self._member = data.get('member', None)
258+
self._user = data.get('user', self._member.get('user'))
256259
self.__interaction_id = data.get('id', 0)
257260
self._guild_id = data.get('guild_id', 0)
258261
self._channel_id = data.get('channel_id', 0)
259262
self.__application_id = data.get('application_id', 0)
260263
self.guild = None
261264
self.channel = None
262265
self.member: Member = None
263-
self.user = None
264-
self._user = dict(self.member._user) if self.member else data.get('user')
266+
self.user: User = None
265267
self.button = ClickEvent(self._data)
266268
self.message: Message = None
267269
self._deferred = False
@@ -276,7 +278,8 @@ async def defer(self, ):
276278
try:
277279
await self.http.post_initial_response(_resp=base, use_webhook=False, interaction_id=self.__interaction_id, token=self.__token, application_id=self.__application_id)
278280
except NotFound:
279-
pass
281+
sys.stderr.write(f'You have already replied to this interaction ({self.__interaction_id})\nand/or 15 minutes have passed since the interaction, which is why'
282+
f' Discord has deleted the interaction.')
280283
else:
281284
self._deferred = True
282285

discord/state.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,6 @@ def parse_message_update(self, data):
535535
self.dispatch('raw_message_edit', raw)
536536

537537
def parse_interaction_create(self, data):
538-
539538
if data.get('type', data.get('t', None)) != 3:
540539
#to make sure that other-libraries like `discord-py-slash-command` still work
541540
self.dispatch('socket_responce', data)
@@ -548,8 +547,7 @@ def parse_interaction_create(self, data):
548547
raw.member: Member = Member(guild=raw.guild, data=raw._member, state=self)
549548
else:
550549
raw.channel = self._get_private_channel(raw.channel_id)
551-
if raw._user is not None:
552-
raw.user = self.get_user(raw._user.get('id', None))
550+
raw.user = User(state=self, data=raw._user)
553551
if raw.message is not None:
554552
self.dispatch('interaction_create', raw)
555553
self.dispatch('raw_interaction_create', raw)

0 commit comments

Comments
 (0)