Skip to content

Commit

Permalink
fix: provide a fake default_role
Browse files Browse the repository at this point in the history
  • Loading branch information
onerandomusername committed Sep 23, 2024
1 parent ceac6eb commit 5e7b9bc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions disnake/interactions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,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 = data.get("guild")
self._guild: Optional[Mapping[str, Any]] = data.get("guild")

self.locale: Locale = try_enum(Locale, data["locale"])
guild_locale = data.get("guild_locale")
Expand Down Expand Up @@ -272,7 +272,16 @@ def guild(self) -> Optional[Guild]:
if self.guild_id is None:
return None

return self._state._get_guild(self.guild_id) or Guild(data=self._guild, state=self._state)
guild = self._state._get_guild(self.guild_id)
if guild:
return guild

# 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)

Check failure on line 282 in disnake/interactions/base.py

View workflow job for this annotation

GitHub Actions / pyright (3.8, false)

Argument of type "Mapping[str, Any] | None" cannot be assigned to parameter "data" of type "Guild" in function "__init__"   Type "Mapping[str, Any] | None" cannot be assigned to type "Guild"     "Mapping[str, Any]" is incompatible with "Guild" (reportGeneralTypeIssues)
guild._add_role(Role(state=self._state, guild=guild, data={"id": 1, "name": "@everyone"}))

Check failure on line 283 in disnake/interactions/base.py

View workflow job for this annotation

GitHub Actions / pyright (3.8, false)

Argument of type "dict[str, int | str]" cannot be assigned to parameter "data" of type "Role" in function "__init__"   "color" is required in "Role"   "hoist" is required in "Role"   "position" is required in "Role"   "permissions" is required in "Role"   "managed" is required in "Role"   "mentionable" is required in "Role"   "flags" is required in "Role" (reportGeneralTypeIssues)
return guild

@utils.cached_slot_property("_cs_me")
def me(self) -> Union[Member, ClientUser]:
Expand Down

0 comments on commit 5e7b9bc

Please sign in to comment.