Skip to content

Commit

Permalink
Implement ForumChannelConverter (#1440)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorukyum authored Jun 23, 2022
1 parent c9870e1 commit 943cc56
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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

0 comments on commit 943cc56

Please sign in to comment.