Skip to content

Commit fc05d78

Browse files
fix typing issues
1 parent e4e27c0 commit fc05d78

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

disnake/interactions/base.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
from ..poll import Poll
7676
from ..state import ConnectionState
7777
from ..types.components import Modal as ModalPayload
78+
from ..types.guild import PartialGuild as PartialGuildPayload
7879
from ..types.interactions import (
7980
ApplicationCommandOptionChoice as ApplicationCommandOptionChoicePayload,
8081
Interaction as InteractionPayload,
@@ -204,7 +205,7 @@ def __init__(self, *, data: InteractionPayload, state: ConnectionState) -> None:
204205
self.version: int = data["version"]
205206
self.application_id: int = int(data["application_id"])
206207
self.guild_id: Optional[int] = utils._get_as_snowflake(data, "guild_id")
207-
self._guild: Optional[Mapping[str, Any]] = data.get("guild")
208+
self._guild: Optional[PartialGuildPayload] = data.get("guild")
208209

209210
self.locale: Locale = try_enum(Locale, data["locale"])
210211
guild_locale = data.get("guild_locale")
@@ -275,12 +276,20 @@ def guild(self) -> Optional[Guild]:
275276
guild = self._state._get_guild(self.guild_id)
276277
if guild:
277278
return guild
279+
if self._guild is None:
280+
return None
278281

279282
# create a guild mash
280283
# honestly we should cache this for the duration of the interaction
281284
# but not if we fetch it from the cache, just the result of this creation
282285
guild = Guild(data=self._guild, state=self._state)
283-
guild._add_role(Role(state=self._state, guild=guild, data={"id": 1, "name": "@everyone"}))
286+
guild._add_role(
287+
Role(
288+
state=self._state,
289+
guild=guild,
290+
data={"id": 1, "name": "@everyone"}, # type: ignore
291+
)
292+
)
284293
return guild
285294

286295
@utils.cached_slot_property("_cs_me")

disnake/types/guild.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ class Guild(_BaseGuildPreview):
149149
guild_scheduled_events: NotRequired[List[GuildScheduledEvent]]
150150

151151

152+
class PartialGuild(Guild, total=False):
153+
pass
154+
155+
152156
class InviteGuild(Guild, total=False):
153157
welcome_screen: WelcomeScreen
154158

disnake/types/interactions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .components import Component, Modal
1111
from .embed import Embed
1212
from .entitlement import Entitlement
13+
from .guild import PartialGuild
1314
from .i18n import LocalizationDict
1415
from .member import Member, MemberWithUser
1516
from .role import Role
@@ -265,6 +266,7 @@ class _BaseUserInteraction(_BaseInteraction):
265266
locale: str
266267
app_permissions: NotRequired[str]
267268
guild_id: NotRequired[Snowflake]
269+
guild: NotRequired[PartialGuild]
268270
guild_locale: NotRequired[str]
269271
entitlements: NotRequired[List[Entitlement]]
270272
# one of these two will always exist, according to docs

0 commit comments

Comments
 (0)