aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoggieLicc <[email protected]>2021-04-03 22:50:17 -0400
committerGitHub <[email protected]>2021-04-03 22:50:17 -0400
commit36318bd45c6aa4c11e77a4aa66b89a07bd963929 (patch)
treeb187dba4c8c425c55aa143f4deb70c6e04b7c913
parentImplement StageChannel and related methods (diff)
downloaddiscord.py-36318bd45c6aa4c11e77a4aa66b89a07bd963929.tar.xz
discord.py-36318bd45c6aa4c11e77a4aa66b89a07bd963929.zip
[commands] Add StoreChannelConverter
-rw-r--r--discord/ext/commands/converter.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/discord/ext/commands/converter.py b/discord/ext/commands/converter.py
index afbea4f2..10e0fa23 100644
--- a/discord/ext/commands/converter.py
+++ b/discord/ext/commands/converter.py
@@ -51,6 +51,7 @@ __all__ = (
'PartialEmojiConverter',
'CategoryChannelConverter',
'IDConverter',
+ 'StoreChannelConverter',
'clean_content',
'Greedy',
)
@@ -478,6 +479,45 @@ class CategoryChannelConverter(IDConverter):
raise ChannelNotFound(argument)
return result
+
+class StoreChannelConverter(IDConverter):
+ """Converts to a :class:`~discord.StoreChannel`.
+
+ 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
+ """
+
+ async def convert(self, ctx, argument):
+ bot = ctx.bot
+ match = self._get_id_match(argument) or re.match(r'<#([0-9]+)>$', argument)
+ result = None
+ guild = ctx.guild
+
+ if match is None:
+ # not a mention
+ if guild:
+ result = discord.utils.get(guild.channels, name=argument)
+ else:
+ def check(c):
+ return isinstance(c, discord.StoreChannel) and c.name == argument
+ result = discord.utils.find(check, bot.get_all_channels())
+ else:
+ channel_id = int(match.group(1))
+ if guild:
+ result = guild.get_channel(channel_id)
+ else:
+ result = _get_from_guilds(bot, 'get_channel', channel_id)
+
+ if not isinstance(result, discord.StoreChannel):
+ raise ChannelNotFound(argument)
+
+ return result
class ColourConverter(Converter):
"""Converts to a :class:`~discord.Colour`.