Browse Source

Add Interaction.locale and Interaction.guild_locale

Co-authored-by: Stocker <[email protected]>
Co-authored-by: Danny <[email protected]>
pull/7589/head
Leo 3 years ago
committed by GitHub
parent
commit
02310e4abd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      discord/interactions.py
  2. 2
      discord/types/interactions.py

15
discord/interactions.py

@ -30,7 +30,7 @@ import asyncio
import datetime import datetime
from . import utils 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 .errors import InteractionResponded, HTTPException, ClientException
from .flags import MessageFlags from .flags import MessageFlags
from .channel import PartialMessageable, ChannelType from .channel import PartialMessageable, ChannelType
@ -103,6 +103,10 @@ class Interaction:
for 15 minutes. for 15 minutes.
data: :class:`dict` data: :class:`dict`
The raw interaction data. 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, ...] = ( __slots__: Tuple[str, ...] = (
@ -116,6 +120,8 @@ class Interaction:
'user', 'user',
'token', 'token',
'version', 'version',
'locale',
'guild_locale',
'_permissions', '_permissions',
'_state', '_state',
'_client', '_client',
@ -143,6 +149,13 @@ class Interaction:
self.guild_id: Optional[int] = utils._get_as_snowflake(data, 'guild_id') self.guild_id: Optional[int] = utils._get_as_snowflake(data, 'guild_id')
self.application_id: int = int(data['application_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] self.message: Optional[Message]
try: try:
# The channel and message payloads are mismatched yet handled properly at runtime # The channel and message payloads are mismatched yet handled properly at runtime

2
discord/types/interactions.py

@ -201,6 +201,8 @@ InteractionData = Union[
class _BaseInteractionOptional(TypedDict, total=False): class _BaseInteractionOptional(TypedDict, total=False):
guild_id: Snowflake guild_id: Snowflake
channel_id: Snowflake channel_id: Snowflake
locale: str
guild_locale: str
class _BaseInteraction(_BaseInteractionOptional): class _BaseInteraction(_BaseInteractionOptional):

Loading…
Cancel
Save