From 1ca8f16924f3b55719e6c71de50f05f39c3cf5eb Mon Sep 17 00:00:00 2001 From: Mantou Date: Mon, 22 Jul 2024 15:34:27 +0800 Subject: [PATCH] refactor: Modified the code to comply with the review suggestions --- disnake/abc.py | 4 ++-- disnake/audit_logs.py | 6 +++--- disnake/channel.py | 16 ++++++++-------- disnake/client.py | 6 +++--- disnake/components.py | 4 ++-- disnake/emoji.py | 13 ++++++++----- disnake/guild.py | 6 +++--- disnake/message.py | 6 +++--- disnake/onboarding.py | 4 ++-- disnake/partial_emoji.py | 4 ++-- disnake/reaction.py | 4 ++-- disnake/state.py | 18 ++++++++---------- disnake/threads.py | 8 ++++---- disnake/ui/action_row.py | 4 ++-- disnake/ui/button.py | 12 ++++++------ disnake/ui/select/string.py | 4 ++-- disnake/welcome_screen.py | 6 +++--- 17 files changed, 63 insertions(+), 62 deletions(-) diff --git a/disnake/abc.py b/disnake/abc.py index c021def827..6d69fbf2c6 100644 --- a/disnake/abc.py +++ b/disnake/abc.py @@ -67,7 +67,7 @@ from .channel import CategoryChannel, DMChannel, PartialMessageable from .client import Client from .embeds import Embed - from .emoji import ApplicationEmoji, Emoji + from .emoji import AnyEmoji from .enums import InviteTarget from .guild import Guild, GuildMessageable from .guild_scheduled_event import GuildScheduledEvent @@ -338,7 +338,7 @@ async def _edit( video_quality_mode: VideoQualityMode = MISSING, flags: ChannelFlags = MISSING, available_tags: Sequence[ForumTag] = MISSING, - default_reaction: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = MISSING, + default_reaction: Optional[Union[str, AnyEmoji, PartialEmoji]] = MISSING, default_sort_order: Optional[ThreadSortOrder] = MISSING, default_layout: ThreadLayout = MISSING, reason: Optional[str] = None, diff --git a/disnake/audit_logs.py b/disnake/audit_logs.py index 106759715f..8d623d66ab 100644 --- a/disnake/audit_logs.py +++ b/disnake/audit_logs.py @@ -43,7 +43,7 @@ from .app_commands import APIApplicationCommand from .automod import AutoModRule - from .emoji import ApplicationEmoji, Emoji + from .emoji import AnyEmoji, Emoji from .guild import Guild from .guild_scheduled_event import GuildScheduledEvent from .integrations import PartialIntegration @@ -280,7 +280,7 @@ def _transform_automod_trigger_metadata( def _transform_default_reaction( entry: AuditLogEntry, data: Optional[DefaultReactionPayload] -) -> Optional[Union[Emoji, ApplicationEmoji, PartialEmoji]]: +) -> Optional[Union[AnyEmoji, PartialEmoji]]: if data is None: return None return entry._state._get_emoji_from_fields( @@ -817,7 +817,7 @@ def _convert_target_invite(self, target_id: int) -> Invite: def _convert_target_webhook(self, target_id: int) -> Union[Webhook, Object]: return self._webhooks.get(target_id) or Object(id=target_id) - def _convert_target_emoji(self, target_id: int) -> Union[Emoji, ApplicationEmoji, Object]: + def _convert_target_emoji(self, target_id: int) -> Union[AnyEmoji, Object]: return self._state.get_emoji(target_id) or Object(id=target_id) def _convert_target_message(self, target_id: int) -> Union[Member, User, Object, None]: diff --git a/disnake/channel.py b/disnake/channel.py index c390fa19fb..716d69f229 100644 --- a/disnake/channel.py +++ b/disnake/channel.py @@ -69,7 +69,7 @@ from .abc import Snowflake, SnowflakeTime from .asset import AssetBytes from .embeds import Embed - from .emoji import ApplicationEmoji, Emoji + from .emoji import AnyEmoji from .guild import Guild, GuildChannel as GuildChannelType from .member import Member, VoiceState from .message import AllowedMentions, Message, PartialMessage @@ -3314,7 +3314,7 @@ def requires_tag(self) -> bool: return self.flags.require_tag @property - def default_reaction(self) -> Optional[Union[Emoji, ApplicationEmoji, PartialEmoji]]: + def default_reaction(self) -> Optional[Union[AnyEmoji, PartialEmoji]]: """Optional[Union[:class:`Emoji`, :class:`PartialEmoji`]]: The default emoji shown for reacting to threads. @@ -3932,7 +3932,7 @@ async def edit( flags: ChannelFlags = ..., require_tag: bool = ..., available_tags: Sequence[ForumTag] = ..., - default_reaction: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = ..., + default_reaction: Optional[Union[str, AnyEmoji, PartialEmoji]] = ..., default_sort_order: Optional[ThreadSortOrder] = ..., default_layout: ThreadLayout = ..., reason: Optional[str] = ..., @@ -3955,7 +3955,7 @@ async def edit( flags: ChannelFlags = MISSING, require_tag: bool = MISSING, available_tags: Sequence[ForumTag] = MISSING, - default_reaction: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = MISSING, + default_reaction: Optional[Union[str, AnyEmoji, PartialEmoji]] = MISSING, default_sort_order: Optional[ThreadSortOrder] = MISSING, default_layout: ThreadLayout = MISSING, reason: Optional[str] = None, @@ -4102,7 +4102,7 @@ async def clone( default_thread_slowmode_delay: Optional[int] = MISSING, default_auto_archive_duration: Optional[AnyThreadArchiveDuration] = MISSING, available_tags: Sequence[ForumTag] = MISSING, - default_reaction: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = MISSING, + default_reaction: Optional[Union[str, AnyEmoji, PartialEmoji]] = MISSING, default_sort_order: Optional[ThreadSortOrder] = MISSING, default_layout: ThreadLayout = MISSING, overwrites: Mapping[Union[Role, Member], PermissionOverwrite] = MISSING, @@ -4362,7 +4362,7 @@ async def edit( flags: ChannelFlags = ..., require_tag: bool = ..., available_tags: Sequence[ForumTag] = ..., - default_reaction: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = ..., + default_reaction: Optional[Union[str, AnyEmoji, PartialEmoji]] = ..., default_sort_order: Optional[ThreadSortOrder] = ..., reason: Optional[str] = ..., ) -> MediaChannel: @@ -4384,7 +4384,7 @@ async def edit( flags: ChannelFlags = MISSING, require_tag: bool = MISSING, available_tags: Sequence[ForumTag] = MISSING, - default_reaction: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = MISSING, + default_reaction: Optional[Union[str, AnyEmoji, PartialEmoji]] = MISSING, default_sort_order: Optional[ThreadSortOrder] = MISSING, reason: Optional[str] = None, **kwargs: Never, @@ -4503,7 +4503,7 @@ async def clone( default_thread_slowmode_delay: Optional[int] = MISSING, default_auto_archive_duration: Optional[AnyThreadArchiveDuration] = MISSING, available_tags: Sequence[ForumTag] = MISSING, - default_reaction: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = MISSING, + default_reaction: Optional[Union[str, AnyEmoji, PartialEmoji]] = MISSING, default_sort_order: Optional[ThreadSortOrder] = MISSING, overwrites: Mapping[Union[Role, Member], PermissionOverwrite] = MISSING, reason: Optional[str] = None, diff --git a/disnake/client.py b/disnake/client.py index 4e5c23e0bb..dbbe26be52 100644 --- a/disnake/client.py +++ b/disnake/client.py @@ -46,7 +46,7 @@ from .application_role_connection import ApplicationRoleConnectionMetadata from .backoff import ExponentialBackoff from .channel import PartialMessageable, _threaded_channel_factory -from .emoji import ApplicationEmoji, GuildEmoji +from .emoji import AnyEmoji, ApplicationEmoji from .entitlement import Entitlement from .enums import ApplicationCommandType, ChannelType, Event, Status from .errors import ( @@ -566,7 +566,7 @@ def guilds(self) -> List[Guild]: return self._connection.guilds @property - def emojis(self) -> List[Union[GuildEmoji, ApplicationEmoji]]: + def emojis(self) -> List[AnyEmoji]: """The emojis that the connected client has. .. note:: @@ -1486,7 +1486,7 @@ def get_user(self, id: int, /) -> Optional[User]: """ return self._connection.get_user(id) - def get_emoji(self, id: int, /) -> Optional[Union[GuildEmoji, ApplicationEmoji]]: + def get_emoji(self, id: int, /) -> Optional[AnyEmoji]: """Returns an emoji with the given ID. Parameters diff --git a/disnake/components.py b/disnake/components.py index 081854308b..ba647c2d50 100644 --- a/disnake/components.py +++ b/disnake/components.py @@ -25,7 +25,7 @@ if TYPE_CHECKING: from typing_extensions import Self, TypeAlias - from .emoji import ApplicationEmoji, Emoji + from .emoji import AnyEmoji from .types.components import ( ActionRow as ActionRowPayload, AnySelectMenu as AnySelectMenuPayload, @@ -546,7 +546,7 @@ def __init__( label: str, value: str = MISSING, description: Optional[str] = None, - emoji: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = None, + emoji: Optional[Union[str, AnyEmoji, PartialEmoji]] = None, default: bool = False, ) -> None: self.label = label diff --git a/disnake/emoji.py b/disnake/emoji.py index 3bc95ca9da..31123309a4 100644 --- a/disnake/emoji.py +++ b/disnake/emoji.py @@ -9,7 +9,7 @@ from .user import User from .utils import MISSING, SnowflakeList, snowflake_time -__all__ = ("BaseEmoji", "Emoji", "GuildEmoji", "ApplicationEmoji") +__all__ = ("BaseEmoji", "Emoji", "GuildEmoji", "ApplicationEmoji", "AnyEmoji") if TYPE_CHECKING: from datetime import datetime @@ -67,8 +67,6 @@ class BaseEmoji(_EmojiTag, AssetMixin): Whether the emoji is animated or not. managed: :class:`bool` Whether the emoji is managed by a Twitch integration. - guild_id: :class:`int` - The guild ID the emoji belongs to. available: :class:`bool` Whether the emoji is available for use. user: Optional[:class:`User`] @@ -84,8 +82,6 @@ class BaseEmoji(_EmojiTag, AssetMixin): "id", "name", "_roles", - "guild_id", - "application_id", "user", "available", ) @@ -197,6 +193,8 @@ class GuildEmoji(BaseEmoji): having the :attr:`~Permissions.manage_guild_expressions` permission. """ + __slots__: Tuple[str, ...] = BaseEmoji.__slots__ + ("guild_id",) + def __init__( self, *, guild: Union[Guild, GuildPreview], state: ConnectionState, data: EmojiPayload ) -> None: @@ -365,6 +363,8 @@ class ApplicationEmoji(BaseEmoji): The user that created the emoji. """ + __slots__: Tuple[str, ...] = BaseEmoji.__slots__ + ("application_id",) + def __init__(self, *, application_id: int, state: ConnectionState, data: EmojiPayload) -> None: self.application_id: int = application_id super().__init__(state=state, data=data) @@ -426,3 +426,6 @@ async def edit( self.application_id, self.id, payload=payload ) return self._state.store_application_emoji(self.application_id, data) + + +AnyEmoji = Union[GuildEmoji, ApplicationEmoji] diff --git a/disnake/guild.py b/disnake/guild.py index 52dd3e3b46..eb6b0b16eb 100644 --- a/disnake/guild.py +++ b/disnake/guild.py @@ -40,7 +40,7 @@ _threaded_guild_channel_factory, ) from .colour import Colour -from .emoji import ApplicationEmoji, Emoji +from .emoji import AnyEmoji, Emoji from .enums import ( AuditLogAction, AutoModEventType, @@ -1643,7 +1643,7 @@ async def create_forum_channel( nsfw: bool = MISSING, overwrites: Dict[Union[Role, Member], PermissionOverwrite] = MISSING, available_tags: Optional[Sequence[ForumTag]] = None, - default_reaction: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = None, + default_reaction: Optional[Union[str, AnyEmoji, PartialEmoji]] = None, default_sort_order: Optional[ThreadSortOrder] = None, default_layout: Optional[ThreadLayout] = None, reason: Optional[str] = None, @@ -1793,7 +1793,7 @@ async def create_media_channel( nsfw: bool = MISSING, overwrites: Dict[Union[Role, Member], PermissionOverwrite] = MISSING, available_tags: Optional[Sequence[ForumTag]] = None, - default_reaction: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = None, + default_reaction: Optional[Union[str, AnyEmoji, PartialEmoji]] = None, default_sort_order: Optional[ThreadSortOrder] = None, reason: Optional[str] = None, ) -> MediaChannel: diff --git a/disnake/message.py b/disnake/message.py index 7cdef7a6aa..d255c59617 100644 --- a/disnake/message.py +++ b/disnake/message.py @@ -25,7 +25,7 @@ from . import utils from .components import ActionRow, MessageComponent, _component_factory from .embeds import Embed -from .emoji import ApplicationEmoji, Emoji +from .emoji import AnyEmoji from .enums import ChannelType, InteractionType, MessageType, try_enum, try_enum_to_int from .errors import HTTPException from .file import File @@ -76,7 +76,7 @@ from .ui.action_row import Components, MessageUIComponent from .ui.view import View - EmojiInputType = Union[Emoji, ApplicationEmoji, PartialEmoji, str] + EmojiInputType = Union[AnyEmoji, PartialEmoji, str] __all__ = ( "Attachment", @@ -93,7 +93,7 @@ def convert_emoji_reaction(emoji: Union[EmojiInputType, Reaction]) -> str: if isinstance(emoji, Reaction): emoji = emoji.emoji - if isinstance(emoji, Emoji) or isinstance(emoji, ApplicationEmoji): + if isinstance(emoji, AnyEmoji): return f"{emoji.name}:{emoji.id}" if isinstance(emoji, PartialEmoji): return emoji._as_reaction() diff --git a/disnake/onboarding.py b/disnake/onboarding.py index 97b42e72fc..e081f256a4 100644 --- a/disnake/onboarding.py +++ b/disnake/onboarding.py @@ -7,7 +7,7 @@ from .mixins import Hashable if TYPE_CHECKING: - from .emoji import ApplicationEmoji, Emoji, PartialEmoji + from .emoji import AnyEmoji, PartialEmoji from .guild import Guild, GuildChannel from .role import Role from .types.onboarding import ( @@ -170,7 +170,7 @@ def __init__(self, *, guild: Guild, data: OnboardingPromptOptionPayload) -> None else frozenset() ) - self.emoji: Optional[Union[Emoji, ApplicationEmoji, PartialEmoji, str]] + self.emoji: Optional[Union[AnyEmoji, PartialEmoji, str]] if emoji_data := data.get("emoji"): self.emoji = guild._state.get_reaction_emoji(emoji_data) else: diff --git a/disnake/partial_emoji.py b/disnake/partial_emoji.py index f9b03510b7..59a9fa8f25 100644 --- a/disnake/partial_emoji.py +++ b/disnake/partial_emoji.py @@ -15,7 +15,7 @@ from typing_extensions import Self - from .emoji import ApplicationEmoji, Emoji + from .emoji import AnyEmoji from .state import ConnectionState from .types.activity import ActivityEmoji as ActivityEmojiPayload from .types.emoji import Emoji as EmojiPayload, PartialEmoji as PartialEmojiPayload @@ -254,7 +254,7 @@ async def read(self) -> bytes: # (e.g. default reaction, tag emoji) @staticmethod def _emoji_to_name_id( - emoji: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] + emoji: Optional[Union[str, AnyEmoji, PartialEmoji]] ) -> Tuple[Optional[str], Optional[int]]: if emoji is None: return None, None diff --git a/disnake/reaction.py b/disnake/reaction.py index 1663aa1d65..6c3925e8a3 100644 --- a/disnake/reaction.py +++ b/disnake/reaction.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: from .abc import Snowflake - from .emoji import ApplicationEmoji, Emoji + from .emoji import AnyEmoji, Emoji from .message import Message from .partial_emoji import PartialEmoji from .types.message import Reaction as ReactionPayload @@ -61,7 +61,7 @@ def __init__( *, message: Message, data: ReactionPayload, - emoji: Optional[Union[PartialEmoji, Emoji, ApplicationEmoji, str]] = None, + emoji: Optional[Union[PartialEmoji, AnyEmoji, str]] = None, ) -> None: self.message: Message = message # _get_emoji_from_data won't return None diff --git a/disnake/state.py b/disnake/state.py index 9c653f0f17..3cb979c0c6 100644 --- a/disnake/state.py +++ b/disnake/state.py @@ -44,7 +44,7 @@ VoiceChannel, _guild_channel_factory, ) -from .emoji import ApplicationEmoji, Emoji, GuildEmoji +from .emoji import AnyEmoji, ApplicationEmoji, GuildEmoji from .entitlement import Entitlement from .enums import ApplicationCommandType, ChannelType, ComponentType, MessageType, Status, try_enum from .flags import ApplicationFlags, Intents, MemberCacheFlags @@ -296,7 +296,7 @@ def clear( # - the weakref slot + object in user objects likely results in a small increase in memory usage # - accesses on `_users` are slower, e.g. `__getitem__` takes ~1us with weakrefs and ~0.2us without self._users: weakref.WeakValueDictionary[int, User] = weakref.WeakValueDictionary() - self._emojis: Dict[int, Union[GuildEmoji, ApplicationEmoji]] = {} + self._emojis: Dict[int, AnyEmoji] = {} self._stickers: Dict[int, GuildSticker] = {} self._guilds: Dict[int, Guild] = {} @@ -518,18 +518,18 @@ def _get_guild_command_named( return cmd @property - def emojis(self) -> List[Union[GuildEmoji, ApplicationEmoji]]: + def emojis(self) -> List[AnyEmoji]: return list(self._emojis.values()) @property def stickers(self) -> List[GuildSticker]: return list(self._stickers.values()) - def get_emoji(self, emoji_id: Optional[int]) -> Optional[Union[GuildEmoji, ApplicationEmoji]]: + def get_emoji(self, emoji_id: Optional[int]) -> Optional[AnyEmoji]: # the keys of self._emojis are ints return self._emojis.get(emoji_id) # type: ignore - def _remove_emoji(self, emoji: Union[GuildEmoji, ApplicationEmoji]) -> None: + def _remove_emoji(self, emoji: AnyEmoji) -> None: self._emojis.pop(emoji.id, None) def get_sticker(self, sticker_id: Optional[int]) -> Optional[GuildSticker]: @@ -1942,7 +1942,7 @@ def _get_reaction_user( def _get_emoji_from_data( self, data: PartialEmojiPayload - ) -> Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]]: + ) -> Optional[Union[str, AnyEmoji, PartialEmoji]]: """Convert partial emoji data to proper emoji. Returns unicode emojis as strings. @@ -1973,7 +1973,7 @@ def _get_emoji_from_fields( name: Optional[str], id: Optional[int], animated: Optional[bool] = False, - ) -> Optional[Union[Emoji, ApplicationEmoji, PartialEmoji]]: + ) -> Optional[Union[AnyEmoji, PartialEmoji]]: """Convert partial emoji fields to proper emoji, if possible. If both `id` and `name` are nullish, returns `None`. @@ -1999,9 +1999,7 @@ def _get_emoji_from_fields( animated=animated or False, ) - def _upgrade_partial_emoji( - self, emoji: PartialEmoji - ) -> Union[Emoji, ApplicationEmoji, PartialEmoji, str]: + def _upgrade_partial_emoji(self, emoji: PartialEmoji) -> Union[AnyEmoji, PartialEmoji, str]: emoji_id = emoji.id if not emoji_id: return emoji.name diff --git a/disnake/threads.py b/disnake/threads.py index 024d35cc0c..ae609a6790 100644 --- a/disnake/threads.py +++ b/disnake/threads.py @@ -28,7 +28,7 @@ from .abc import Snowflake, SnowflakeTime from .channel import CategoryChannel, ForumChannel, MediaChannel, TextChannel - from .emoji import ApplicationEmoji, Emoji + from .emoji import AnyEmoji from .guild import Guild from .member import Member from .message import Message, PartialMessage @@ -1157,14 +1157,14 @@ def __init__( self, *, name: str, - emoji: Optional[Union[str, PartialEmoji, ApplicationEmoji, Emoji]] = None, + emoji: Optional[Union[str, PartialEmoji, AnyEmoji]] = None, moderated: bool = False, ) -> None: self.id: int = 0 self.name: str = name self.moderated: bool = moderated - self.emoji: Optional[Union[Emoji, ApplicationEmoji, PartialEmoji]] = None + self.emoji: Optional[Union[AnyEmoji, PartialEmoji]] = None if emoji is None: self.emoji = None elif isinstance(emoji, str): @@ -1225,7 +1225,7 @@ def with_changes( self, *, name: str = MISSING, - emoji: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = MISSING, + emoji: Optional[Union[str, AnyEmoji, PartialEmoji]] = MISSING, moderated: bool = MISSING, ) -> Self: """Returns a new instance with the given changes applied, diff --git a/disnake/ui/action_row.py b/disnake/ui/action_row.py index 2a67770241..ef9337b582 100644 --- a/disnake/ui/action_row.py +++ b/disnake/ui/action_row.py @@ -40,7 +40,7 @@ if TYPE_CHECKING: from typing_extensions import Self - from ..emoji import ApplicationEmoji, Emoji + from ..emoji import AnyEmoji from ..message import Message from ..partial_emoji import PartialEmoji from ..types.components import ActionRow as ActionRowPayload @@ -245,7 +245,7 @@ def add_button( disabled: bool = False, custom_id: Optional[str] = None, url: Optional[str] = None, - emoji: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = None, + emoji: Optional[Union[str, AnyEmoji, PartialEmoji]] = None, ) -> ButtonCompatibleActionRowT: """Add a button to the action row. Can only be used if the action row holds message components. diff --git a/disnake/ui/button.py b/disnake/ui/button.py index 4ed98b16c3..e22d2b0206 100644 --- a/disnake/ui/button.py +++ b/disnake/ui/button.py @@ -31,7 +31,7 @@ if TYPE_CHECKING: from typing_extensions import ParamSpec, Self - from ..emoji import ApplicationEmoji, Emoji + from ..emoji import AnyEmoji from .item import ItemCallbackType from .view import View @@ -92,7 +92,7 @@ def __init__( disabled: bool = False, custom_id: Optional[str] = None, url: Optional[str] = None, - emoji: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = None, + emoji: Optional[Union[str, AnyEmoji, PartialEmoji]] = None, row: Optional[int] = None, ) -> None: ... @@ -106,7 +106,7 @@ def __init__( disabled: bool = False, custom_id: Optional[str] = None, url: Optional[str] = None, - emoji: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = None, + emoji: Optional[Union[str, AnyEmoji, PartialEmoji]] = None, row: Optional[int] = None, ) -> None: ... @@ -119,7 +119,7 @@ def __init__( disabled: bool = False, custom_id: Optional[str] = None, url: Optional[str] = None, - emoji: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = None, + emoji: Optional[Union[str, AnyEmoji, PartialEmoji]] = None, row: Optional[int] = None, ) -> None: super().__init__() @@ -217,7 +217,7 @@ def emoji(self) -> Optional[PartialEmoji]: return self._underlying.emoji @emoji.setter - def emoji(self, value: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]]) -> None: + def emoji(self, value: Optional[Union[str, AnyEmoji, PartialEmoji]]) -> None: if value is not None: if isinstance(value, str): self._underlying.emoji = PartialEmoji.from_str(value) @@ -261,7 +261,7 @@ def button( custom_id: Optional[str] = None, disabled: bool = False, style: ButtonStyle = ButtonStyle.secondary, - emoji: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = None, + emoji: Optional[Union[str, AnyEmoji, PartialEmoji]] = None, row: Optional[int] = None, ) -> Callable[[ItemCallbackType[Button[V_co]]], DecoratedItem[Button[V_co]]]: ... diff --git a/disnake/ui/select/string.py b/disnake/ui/select/string.py index e46f12e570..07198b685b 100644 --- a/disnake/ui/select/string.py +++ b/disnake/ui/select/string.py @@ -24,7 +24,7 @@ if TYPE_CHECKING: from typing_extensions import Self - from ...emoji import ApplicationEmoji, Emoji + from ...emoji import AnyEmoji from ...partial_emoji import PartialEmoji from ..item import DecoratedItem, ItemCallbackType, Object @@ -181,7 +181,7 @@ def add_option( label: str, value: str = MISSING, description: Optional[str] = None, - emoji: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = None, + emoji: Optional[Union[str, AnyEmoji, PartialEmoji]] = None, default: bool = False, ) -> None: """Adds an option to the select menu. diff --git a/disnake/welcome_screen.py b/disnake/welcome_screen.py index 8797ef1ccd..28f9058e0f 100644 --- a/disnake/welcome_screen.py +++ b/disnake/welcome_screen.py @@ -8,7 +8,7 @@ from .partial_emoji import PartialEmoji, _EmojiTag if TYPE_CHECKING: - from .emoji import ApplicationEmoji, Emoji + from .emoji import AnyEmoji from .guild import Guild from .invite import PartialInviteGuild from .state import ConnectionState @@ -51,11 +51,11 @@ def __init__( *, id: int, description: str, - emoji: Optional[Union[str, Emoji, ApplicationEmoji, PartialEmoji]] = None, + emoji: Optional[Union[str, AnyEmoji, PartialEmoji]] = None, ) -> None: self.id: int = id self.description: str = description - self.emoji: Optional[Union[Emoji, ApplicationEmoji, PartialEmoji]] = None + self.emoji: Optional[Union[AnyEmoji, PartialEmoji]] = None if emoji is None: self.emoji = None elif isinstance(emoji, str):