Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ForumChannelConverter #1440

Merged
merged 3 commits into from
Jun 23, 2022
Merged
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
20 changes: 20 additions & 0 deletions discord/ext/commands/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,25 @@ async def convert(self, ctx: Context, argument: str) -> discord.CategoryChannel:
return GuildChannelConverter._resolve_channel(ctx, argument, "categories", discord.CategoryChannel)


class ForumChannelConverter(IDConverter[discord.ForumChannel]):
"""Converts to a :class:`~discord.ForumChannel`.

All lookups are via the local guild. If in a DM context, then the lookup
is done by the global cache.

The lookup strategy is as follows (in order):

1. Lookup by ID.
2. Lookup by mention.
3. Lookup by name

.. versionadded:: 2.0
"""

async def convert(self, ctx: Context, argument: str) -> discord.ForumChannel:
return GuildChannelConverter._resolve_channel(ctx, argument, "forum_channels", discord.ForumChannel)


class ThreadConverter(IDConverter[discord.Thread]):
"""Coverts to a :class:`~discord.Thread`.

Expand Down Expand Up @@ -1043,6 +1062,7 @@ def is_generic_type(tp: Any, *, _GenericAlias: Type = _GenericAlias) -> bool:
discord.Emoji: EmojiConverter,
discord.PartialEmoji: PartialEmojiConverter,
discord.CategoryChannel: CategoryChannelConverter,
discord.ForumChannel: ForumChannelConverter,
discord.Thread: ThreadConverter,
discord.abc.GuildChannel: GuildChannelConverter,
discord.GuildSticker: GuildStickerConverter,
Expand Down
3 changes: 3 additions & 0 deletions docs/ext/commands/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ Converters
.. autoclass:: discord.ext.commands.CategoryChannelConverter
:members:

.. autoclass:: discord.ext.commands.ForumChannelConverter
:members:

.. autoclass:: discord.ext.commands.InviteConverter
:members:

Expand Down