From 02310e4abd36e69a2d4c87d59c3e65267fa7d988 Mon Sep 17 00:00:00 2001 From: Leo Date: Mon, 7 Mar 2022 16:34:38 -0800 Subject: [PATCH] Add Interaction.locale and Interaction.guild_locale Co-authored-by: Stocker <44980366+StockerMC@users.noreply.github.com> Co-authored-by: Danny --- discord/interactions.py | 15 ++++++++++++++- discord/types/interactions.py | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/discord/interactions.py b/discord/interactions.py index c5ef87868..ae8c0a5df 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -30,7 +30,7 @@ import asyncio import datetime from . import utils -from .enums import try_enum, InteractionType, InteractionResponseType +from .enums import try_enum, Locale, InteractionType, InteractionResponseType from .errors import InteractionResponded, HTTPException, ClientException from .flags import MessageFlags from .channel import PartialMessageable, ChannelType @@ -103,6 +103,10 @@ class Interaction: for 15 minutes. data: :class:`dict` The raw interaction data. + locale: :class:`Locale` + The locale of the user invoking the interaction. + guild_locale: Optional[:class:`Locale`] + The preferred locale of the guild the interaction was sent from, if any. """ __slots__: Tuple[str, ...] = ( @@ -116,6 +120,8 @@ class Interaction: 'user', 'token', 'version', + 'locale', + 'guild_locale', '_permissions', '_state', '_client', @@ -143,6 +149,13 @@ class Interaction: self.guild_id: Optional[int] = utils._get_as_snowflake(data, 'guild_id') self.application_id: int = int(data['application_id']) + self.locale: Locale = try_enum(Locale, data.get('locale', 'en-US')) + self.guild_locale: Optional[Locale] + try: + self.guild_locale = try_enum(Locale, data.get['guild_locale']) + except KeyError: + self.guild_locale = None + self.message: Optional[Message] try: # The channel and message payloads are mismatched yet handled properly at runtime diff --git a/discord/types/interactions.py b/discord/types/interactions.py index 470ac8754..765b466c7 100644 --- a/discord/types/interactions.py +++ b/discord/types/interactions.py @@ -201,6 +201,8 @@ InteractionData = Union[ class _BaseInteractionOptional(TypedDict, total=False): guild_id: Snowflake channel_id: Snowflake + locale: str + guild_locale: str class _BaseInteraction(_BaseInteractionOptional):