Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions discord/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from typing import TYPE_CHECKING, Any, Literal

import yarl
from typing_extensions import deprecated

from . import utils
from .errors import DiscordException, InvalidArgument
Expand Down Expand Up @@ -149,12 +150,17 @@ class Asset(AssetMixin):
Returns the asset's url's hash.

This is equivalent to hash(:attr:`url`).

Attributes
----------
animated: :class:`bool`
Whether the asset is animated.
"""

__slots__: tuple[str, ...] = (
"_state",
"_url",
"_animated",
"animated",
"_key",
)

Expand All @@ -163,7 +169,7 @@ class Asset(AssetMixin):
def __init__(self, state, *, url: str, key: str, animated: bool = False):
self._state = state
self._url = url
self._animated = animated
self.animated = animated
Comment thread
ToothyDev marked this conversation as resolved.
Outdated
self._key = key

@classmethod
Expand Down Expand Up @@ -377,9 +383,17 @@ def key(self) -> str:
"""Returns the identifying key of the asset."""
return self._key

@deprecated(
"Asset.is_animated() is deprecated since version 2.9, consider using Asset.animated instead"
)
def is_animated(self) -> bool:
"""Returns whether the asset is animated."""
return self._animated
"""Returns whether the asset is animated.

.. deprecated:: 2.9

Use :attr:`animated` instead.
"""
return self.animated

def replace(
self,
Expand Down
46 changes: 35 additions & 11 deletions discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,15 @@ def threads(self) -> list[Thread]:
if thread.parent_id == self.id
]

@deprecated(
"Channel.is_nsfw() is deprecated since version 2.9, consider using Channel.nsfw instead"
)
def is_nsfw(self) -> bool:
"""Checks if the channel is NSFW."""
"""Checks if the channel is NSFW.

.. deprecated:: 2.9
Use :attr:`nsfw` instead.
"""
return self.nsfw

@property
Expand Down Expand Up @@ -751,10 +758,6 @@ class TextChannel(discord.abc.Messageable, _TextChannel):
:attr:`~Permissions.manage_messages` bypass slowmode.
nsfw: :class:`bool`
If the channel is marked as "not safe for work".

.. note::

To check if the channel or the guild of that channel are marked as NSFW, consider :meth:`is_nsfw` instead.
default_auto_archive_duration: :class:`int`
The default auto archive duration in minutes for threads created in this channel.

Expand Down Expand Up @@ -784,14 +787,21 @@ def _update(self, guild: Guild, data: TextChannelPayload) -> None:
async def _get_channel(self) -> TextChannel:
return self

@deprecated(
"TextChannel.is_news() is deprecated since version 2.9, consider using TextChannel.news instead"
)
def is_news(self) -> bool:
"""Checks if the channel is a news/announcements channel."""
return self._type == ChannelType.news.value
"""Checks if the channel is a news/announcements channel.

.. deprecated:: 2.9
Use :attr:`news` instead.
"""
return self.news

@property
def news(self) -> bool:
"""Equivalent to :meth:`is_news`."""
return self.is_news()
"""Checks if the channel is a news/announcements channel."""
return self._type == ChannelType.news.value

@overload
async def edit(
Expand Down Expand Up @@ -1811,8 +1821,15 @@ def __repr__(self) -> str:
async def _get_channel(self):
return self

@deprecated(
"VoiceChannel.is_nsfw() is deprecated since version 2.9, consider using VoiceChannel.nsfw instead."
)
def is_nsfw(self) -> bool:
"""Checks if the channel is NSFW."""
"""Checks if the channel is NSFW.

.. deprecated:: 2.9
Use :attr:`nsfw` instead.
"""
return self.nsfw

@property
Expand Down Expand Up @@ -2399,8 +2416,15 @@ def listeners(self) -> list[Member]:
async def _get_channel(self):
return self

@deprecated(
"StageChannel.is_nsfw() is deprecated since version 2.9, consider using StageChannel.nsfw instead"
)
def is_nsfw(self) -> bool:
"""Checks if the channel is NSFW."""
"""Checks if the channel is NSFW.

.. deprecated:: 2.9
Use :attr:`nsfw` instead.
"""
return self.nsfw

@property
Expand Down
29 changes: 29 additions & 0 deletions discord/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from collections.abc import Iterator
from typing import TYPE_CHECKING, Any, Literal

from typing_extensions import deprecated

from .asset import Asset, AssetMixin
from .partial_emoji import PartialEmoji, _EmojiTag
from .user import User
Expand Down Expand Up @@ -211,10 +213,15 @@ def guild(self) -> Guild:
"""The guild this emoji belongs to."""
return self._state._get_guild(self.guild_id)

@deprecated(
"GuildEmoji.is_usable() is deprecated since version 2.9, consider using GuildEmoji.usable instead"
)
def is_usable(self) -> bool:
"""Whether the bot can use this emoji.

.. versionadded:: 1.3
.. deprecated:: 2.9
Use :attr:`usable` instead.
"""
if not self.available:
return False
Expand All @@ -223,6 +230,16 @@ def is_usable(self) -> bool:
emoji_roles, my_roles = self._roles, self.guild.me._roles
return any(my_roles.has(role_id) for role_id in emoji_roles)
Comment thread
ToothyDev marked this conversation as resolved.
Outdated

@property
def usable(self) -> bool:
"""Whether the bot can use this emoji."""
if not self.available:
return False
if not self._roles:
return True
emoji_roles, my_roles = self._roles, self.guild.me._roles
return any(my_roles.has(role_id) for role_id in emoji_roles)

async def delete(self, *, reason: str | None = None) -> None:
"""|coro|

Expand Down Expand Up @@ -374,7 +391,19 @@ def roles(self) -> list[Role]:
"""A :class:`list` of roles that is allowed to use this emoji. This is always empty for :class:`AppEmoji`."""
return []

@deprecated(
"AppEmoji.is_usable() is deprecated since version 2.9, consider using AppEmoji.usable instead"
)
def is_usable(self) -> bool:
"""Whether the bot can use this emoji.

.. deprecated:: 2.9
Use :attr:`usable` instead.
"""
return self.application_id == self._state.application_id

@property
def usable(self) -> bool:
"""Whether the bot can use this emoji."""
return self.application_id == self._state.application_id

Expand Down
34 changes: 34 additions & 0 deletions discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
)
from urllib.parse import parse_qs, urlparse

from typing_extensions import deprecated

from . import utils
from .channel import PartialMessageable
from .components import _component_factory
Expand Down Expand Up @@ -275,7 +277,19 @@ def issued_at(self) -> datetime.datetime | None:
return None
return datetime.datetime.utcfromtimestamp(int(self._is, 16))

@deprecated(
"Attachment.is_spoiler() is deprecated since version 2.9, consider using Attachment.spoiler instead"
)
def is_spoiler(self) -> bool:
"""Whether this attachment contains a spoiler.

.. deprecated:: 2.9
Use :attr:`spoiler` instead.
"""
return self.filename.startswith("SPOILER_")

@property
def spoiler(self) -> bool:
"""Whether this attachment contains a spoiler."""
return self.filename.startswith("SPOILER_")

Expand Down Expand Up @@ -1505,13 +1519,33 @@ def jump_url(self) -> str:
def poll(self) -> Poll | None:
return self._state._polls.get(self.id)

@deprecated(
"Message.is_system() is deprecated since version 2.9, consider using Message.system instead"
)
def is_system(self) -> bool:
"""Whether the message is a system message.

A system message is a message that is constructed entirely by the Discord API
in response to something.

.. versionadded:: 1.3

.. deprecated:: 2.9
Use :attr:`system` instead.
"""
return self.type not in (
MessageType.default,
MessageType.reply,
MessageType.application_command,
MessageType.thread_starter_message,
)

@property
def system(self) -> bool:
"""Whether the message is a system message.

A system message is a message that is constructed entirely by the Discord API
in response to something.
"""
return self.type not in (
MessageType.default,
Expand Down