diff --git a/disnake/interactions/base.py b/disnake/interactions/base.py index 918e98cddd..4c1291243e 100644 --- a/disnake/interactions/base.py +++ b/disnake/interactions/base.py @@ -75,6 +75,7 @@ from ..poll import Poll from ..state import ConnectionState from ..types.components import Modal as ModalPayload + from ..types.guild import PartialGuild as PartialGuildPayload from ..types.interactions import ( ApplicationCommandOptionChoice as ApplicationCommandOptionChoicePayload, Interaction as InteractionPayload, @@ -204,7 +205,7 @@ def __init__(self, *, data: InteractionPayload, state: ConnectionState) -> None: self.version: int = data["version"] self.application_id: int = int(data["application_id"]) self.guild_id: Optional[int] = utils._get_as_snowflake(data, "guild_id") - self._guild: Optional[Mapping[str, Any]] = data.get("guild") + self._guild: Optional[PartialGuildPayload] = data.get("guild") self.locale: Locale = try_enum(Locale, data["locale"]) guild_locale = data.get("guild_locale") @@ -275,12 +276,20 @@ def guild(self) -> Optional[Guild]: guild = self._state._get_guild(self.guild_id) if guild: return guild + if self._guild is None: + return None # create a guild mash # honestly we should cache this for the duration of the interaction # but not if we fetch it from the cache, just the result of this creation guild = Guild(data=self._guild, state=self._state) - guild._add_role(Role(state=self._state, guild=guild, data={"id": 1, "name": "@everyone"})) + guild._add_role( + Role( + state=self._state, + guild=guild, + data={"id": 1, "name": "@everyone"}, # type: ignore + ) + ) return guild @utils.cached_slot_property("_cs_me") diff --git a/disnake/types/guild.py b/disnake/types/guild.py index 76d8d2f6b5..ee0b6f9296 100644 --- a/disnake/types/guild.py +++ b/disnake/types/guild.py @@ -149,6 +149,10 @@ class Guild(_BaseGuildPreview): guild_scheduled_events: NotRequired[List[GuildScheduledEvent]] +class PartialGuild(Guild, total=False): + pass + + class InviteGuild(Guild, total=False): welcome_screen: WelcomeScreen diff --git a/disnake/types/interactions.py b/disnake/types/interactions.py index 9cb8393ea5..083518d569 100644 --- a/disnake/types/interactions.py +++ b/disnake/types/interactions.py @@ -10,6 +10,7 @@ from .components import Component, Modal from .embed import Embed from .entitlement import Entitlement +from .guild import PartialGuild from .i18n import LocalizationDict from .member import Member, MemberWithUser from .role import Role @@ -265,6 +266,7 @@ class _BaseUserInteraction(_BaseInteraction): locale: str app_permissions: NotRequired[str] guild_id: NotRequired[Snowflake] + guild: NotRequired[PartialGuild] guild_locale: NotRequired[str] entitlements: NotRequired[List[Entitlement]] # one of these two will always exist, according to docs