Skip to content

Commit

Permalink
fix: update typed dicts for commands (#2274)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorukyum authored Dec 14, 2023
1 parent 98c4e19 commit c1a57fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ async def on_connect():
lambda cmd: cmd.name == i["name"]
and cmd.type == i.get("type")
and cmd.guild_ids is not None
# TODO: fix this type error (guild_id is not defined in ApplicationCommand Typed Dict)
and int(i["guild_id"]) in cmd.guild_ids, # type: ignore
and (guild_id := i.get("guild_id"))
and guild_id in cmd.guild_ids,
self.pending_application_commands,
)
if not cmd:
Expand Down
32 changes: 21 additions & 11 deletions discord/types/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,45 @@


class ApplicationCommand(TypedDict):
options: NotRequired[list[ApplicationCommandOption]]
type: NotRequired[ApplicationCommandType]
name_localized: NotRequired[str]
name_localizations: NotRequired[dict[str, str]]
description_localized: NotRequired[str]
description_localizations: NotRequired[dict[str, str]]
id: Snowflake
type: NotRequired[ApplicationCommandType]
application_id: Snowflake
guild_id: NotRequired[Snowflake]
name: str
name_localizations: NotRequired[dict[str, str] | None]
description: str
description_localizations: NotRequired[dict[str, str] | None]
options: NotRequired[list[ApplicationCommandOption]]
default_member_permissions: str | None
dm_permission: NotRequired[bool]
default_permission: NotRequired[bool | None]
nsfw: NotRequired[bool]
version: Snowflake


ApplicationCommandOptionType = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]


class ApplicationCommandOption(TypedDict):
choices: NotRequired[list[ApplicationCommandOptionChoice]]
options: NotRequired[list[ApplicationCommandOption]]
name_localizations: NotRequired[dict[str, str]]
description_localizations: NotRequired[dict[str, str]]
type: ApplicationCommandOptionType
name: str
name_localizations: NotRequired[dict[str, str] | None]
description: str
description_localizations: NotRequired[dict[str, str] | None]
required: bool
options: NotRequired[list[ApplicationCommandOption]]
choices: NotRequired[list[ApplicationCommandOptionChoice]]
channel_types: NotRequired[list[ChannelType]]
min_value: NotRequired[int | float]
max_value: NotRequired[int | float]
min_length: NotRequired[int]
max_length: NotRequired[int]
autocomplete: NotRequired[bool]


class ApplicationCommandOptionChoice(TypedDict):
name_localizations: NotRequired[dict[str, str]]
name: str
name_localizations: NotRequired[dict[str, str] | None]
value: str | int


Expand Down

0 comments on commit c1a57fa

Please sign in to comment.