Add Interaction.locale and Interaction.guild_locale

Co-authored-by: Stocker <44980366+StockerMC@users.noreply.github.com>
Co-authored-by: Danny <Rapptz@users.noreply.github.com>
This commit is contained in:
Leo 2022-03-07 16:34:38 -08:00 committed by GitHub
parent 8213603822
commit 02310e4abd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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):