Skip to content

Commit 4a1bcac

Browse files
authored
fix: edge case error occurring when adding guild IDs to the resolved data in the option dispatching. (#1172)
* fix: edge case * refactor: move import
1 parent 50cea2d commit 4a1bcac

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

interactions/api/gateway/client.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
wait,
1717
wait_for,
1818
)
19+
from contextlib import suppress
1920
from enum import IntEnum
2021
from sys import platform, version_info
2122
from time import perf_counter
@@ -858,8 +859,9 @@ def __option_type_context(self, context: "_Context", type: int) -> dict:
858859
context.data.resolved.members if context.guild_id else context.data.resolved.users
859860
)
860861
if context.guild_id:
861-
for key in _resolved.keys():
862-
_resolved[key]._extras["guild_id"] = context.guild_id
862+
with suppress(AttributeError): # edge-case
863+
for key in _resolved.keys():
864+
_resolved[key]._extras["guild_id"] = context.guild_id
863865
elif type == OptionType.CHANNEL.value:
864866
_resolved = context.data.resolved.channels
865867
elif type == OptionType.ROLE.value:
@@ -872,8 +874,9 @@ def __option_type_context(self, context: "_Context", type: int) -> dict:
872874
context.data.resolved.members if context.guild_id else context.data.resolved.users
873875
)
874876
if context.guild_id:
875-
for key in _members.keys():
876-
_members[key]._extras["guild_id"] = context.guild_id
877+
with suppress(AttributeError): # edge-case
878+
for key in _members.keys():
879+
_members[key]._extras["guild_id"] = context.guild_id
877880

878881
_resolved = {
879882
**(_members if _members is not None else {}),
@@ -901,8 +904,9 @@ def __select_option_type_context(self, context: "_Context", type: int) -> dict:
901904
context.data.resolved.members if context.guild_id else context.data.resolved.users
902905
)
903906
if context.guild_id:
904-
for key in _resolved.keys():
905-
_resolved[key]._extras["guild_id"] = context.guild_id
907+
with suppress(AttributeError): # edge-case
908+
for key in _resolved.keys():
909+
_resolved[key]._extras["guild_id"] = context.guild_id
906910
elif type == ComponentType.CHANNEL_SELECT.value:
907911
_resolved = context.data.resolved.channels
908912
elif type == ComponentType.ROLE_SELECT.value:
@@ -914,8 +918,9 @@ def __select_option_type_context(self, context: "_Context", type: int) -> dict:
914918
else context.data.resolved.users
915919
):
916920
if context.guild_id:
917-
for key in users.keys():
918-
users[key]._extras["guild_id"] = context.guild_id
921+
with suppress(AttributeError): # edge-case
922+
for key in users.keys():
923+
users[key]._extras["guild_id"] = context.guild_id
919924
_resolved.update(**users)
920925
if roles := context.data.resolved.roles:
921926
_resolved.update(**roles)

0 commit comments

Comments
 (0)