Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def add_application_command(self, command: ApplicationCommand) -> None:
command: :class:`.ApplicationCommand`
The command to add.
"""
if isinstance(command, SlashCommand) and command.is_subcommand:
if isinstance(command, SlashCommand) and command.subcommand:
raise TypeError("The provided command is a sub-command of group")

if self._bot.debug_guilds and command.guild_ids is None:
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
48 changes: 42 additions & 6 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ class Client:
The WebSocket gateway the client is currently connected to. Could be ``None``.
loop: :class:`asyncio.AbstractEventLoop`
The event loop that the client uses for asynchronous operations.
closed: :class:`bool`
Indicates if the WebSocket connection is closed.
"""

def __init__(
Expand Down Expand Up @@ -277,7 +279,7 @@ def __init__(
self._enable_debug_events: bool = options.pop("enable_debug_events", False)
self._connection: ConnectionState = self._get_state(**options)
self._connection.shard_count = self.shard_count
self._closed: bool = False
self.closed: bool = False
self._ready: asyncio.Event = asyncio.Event()
self._connection._get_websocket = self._get_websocket
self._connection._get_client = lambda: self
Expand Down Expand Up @@ -337,13 +339,28 @@ def latency(self) -> float:
ws = self.ws
return float("nan") if not ws else ws.latency

@deprecated(
"Client.is_ws_ratelimited() is deprecated since version 2.9, consider using Client.ws_ratelimited instead."
)
def is_ws_ratelimited(self) -> bool:
"""Whether the WebSocket is currently rate limited.

This can be useful to know when deciding whether you should query members
using HTTP or via the gateway.

.. versionadded:: 1.6

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

@property
def ws_ratelimited(self) -> bool:
"""Whether the WebSocket is currently rate limited.

This can be useful to know when deciding whether you should query members
using HTTP or via the gateway.
"""
if self.ws:
return self.ws.is_ratelimited()
Expand Down Expand Up @@ -447,7 +464,19 @@ def application_flags(self) -> ApplicationFlags:
"""
return self._connection.application_flags # type: ignore

@deprecated(
"Client.is_ready() is deprecated since version 2.9, consider using Client.ready instead"
)
def is_ready(self) -> bool:
"""Specifies if the client's internal cache is ready for use.

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

@property
def ready(self) -> bool:
"""Specifies if the client's internal cache is ready for use."""
return self._ready.is_set()

Expand Down Expand Up @@ -779,11 +808,11 @@ async def close(self) -> None:

Closes the connection to Discord.
"""
if self._closed:
if self.closed:
return

await self.http.close()
self._closed = True
self.closed = True

for voice in self.voice_clients:
try:
Expand All @@ -804,7 +833,7 @@ def clear(self) -> None:
and :meth:`is_ready` both return ``False`` along with the bot's internal
cache cleared.
"""
self._closed = False
self.closed = False
self._ready.clear()
self._connection.clear()
self.http.recreate()
Expand Down Expand Up @@ -884,9 +913,16 @@ def stop_loop_on_completion(f):

# properties

@deprecated(
"Client.is_closed() is deprecated since version 2.9, consider using Client.closed instead."
)
def is_closed(self) -> bool:
"""Indicates if the WebSocket connection is closed."""
return self._closed
"""Indicates if the WebSocket connection is closed.

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

@property
def activity(self) -> ActivityTypes | None:
Expand Down
6 changes: 3 additions & 3 deletions discord/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ def cog(self, value):
self._validate_parameters()

@property
def is_subcommand(self) -> bool:
def subcommand(self) -> bool:
return self.parent is not None

@property
Expand All @@ -973,7 +973,7 @@ def to_dict(self) -> dict:
as_dict["name_localizations"] = self.name_localizations
if self.description_localizations is not MISSING:
as_dict["description_localizations"] = self.description_localizations
if self.is_subcommand:
if self.subcommand:
as_dict["type"] = SlashCommandOptionType.sub_command.value

if self.nsfw is not None:
Expand All @@ -984,7 +984,7 @@ def to_dict(self) -> dict:
self.default_member_permissions.value
)

if not self.guild_ids and not self.is_subcommand:
if not self.guild_ids and not self.subcommand:
as_dict["integration_types"] = [it.value for it in self.integration_types]
as_dict["contexts"] = [ctx.value for ctx in self.contexts]

Expand Down
24 changes: 24 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,11 +213,21 @@ 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.
"""
return self.usable

@property
def usable(self) -> bool:
"""Whether the bot can use this emoji."""
if not self.available:
return False
if not self._roles:
Expand Down Expand Up @@ -374,7 +386,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.usable

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

Expand Down
29 changes: 29 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.spoiler

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

Expand Down Expand Up @@ -1505,13 +1519,28 @@ 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.system

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