mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
[commands] Add new MessageConverter to commands prose page.
This commit is contained in:
parent
440db2a568
commit
296d4bf580
@ -159,9 +159,11 @@ class UserConverter(IDConverter):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
class MessageConverter(IDConverter):
|
class MessageConverter:
|
||||||
"""Converts to a :class:`discord.Message`.
|
"""Converts to a :class:`discord.Message`.
|
||||||
|
|
||||||
|
.. versionadded:: 1.1.0
|
||||||
|
|
||||||
The lookup strategy is as follows (in order):
|
The lookup strategy is as follows (in order):
|
||||||
|
|
||||||
1. Lookup by "{channel ID}-{message ID}" (retrieved by shift-clicking on "Copy ID")
|
1. Lookup by "{channel ID}-{message ID}" (retrieved by shift-clicking on "Copy ID")
|
||||||
@ -174,7 +176,7 @@ class MessageConverter(IDConverter):
|
|||||||
link_regex = re.compile(
|
link_regex = re.compile(
|
||||||
r'^https?://(?:(ptb|canary)\.)?discordapp\.com/channels/'
|
r'^https?://(?:(ptb|canary)\.)?discordapp\.com/channels/'
|
||||||
r'(?:([0-9]{15,21})|(@me))'
|
r'(?:([0-9]{15,21})|(@me))'
|
||||||
r'/(?P<channel_id>[0-9]{15,21})/(?P<message_id>[0-9]{15,21})$'
|
r'/(?P<channel_id>[0-9]{15,21})/(?P<message_id>[0-9]{15,21})/?$'
|
||||||
)
|
)
|
||||||
match = id_regex.match(argument) or link_regex.match(argument)
|
match = id_regex.match(argument) or link_regex.match(argument)
|
||||||
if not match:
|
if not match:
|
||||||
@ -189,9 +191,9 @@ class MessageConverter(IDConverter):
|
|||||||
raise BadArgument('Channel "{channel}" not found.'.format(channel=channel_id))
|
raise BadArgument('Channel "{channel}" not found.'.format(channel=channel_id))
|
||||||
try:
|
try:
|
||||||
return await channel.fetch_message(message_id)
|
return await channel.fetch_message(message_id)
|
||||||
except discord.errors.NotFound:
|
except discord.NotFound:
|
||||||
raise BadArgument('Message "{msg}" not found.'.format(msg=argument))
|
raise BadArgument('Message "{msg}" not found.'.format(msg=argument))
|
||||||
except discord.errors.Forbidden:
|
except discord.Forbidden:
|
||||||
raise BadArgument("Can't read messages in {channel}".format(channel=channel.mention))
|
raise BadArgument("Can't read messages in {channel}".format(channel=channel.mention))
|
||||||
|
|
||||||
class TextChannelConverter(IDConverter):
|
class TextChannelConverter(IDConverter):
|
||||||
|
@ -394,6 +394,8 @@ converter is given below:
|
|||||||
+-----------------------+-------------------------------------------------+
|
+-----------------------+-------------------------------------------------+
|
||||||
| :class:`Member` | :class:`~ext.commands.MemberConverter` |
|
| :class:`Member` | :class:`~ext.commands.MemberConverter` |
|
||||||
+-----------------------+-------------------------------------------------+
|
+-----------------------+-------------------------------------------------+
|
||||||
|
| :class:`Message` | :class:`~ext.commands.MessageConverter` |
|
||||||
|
+-----------------------+-------------------------------------------------+
|
||||||
| :class:`User` | :class:`~ext.commands.UserConverter` |
|
| :class:`User` | :class:`~ext.commands.UserConverter` |
|
||||||
+-----------------------+-------------------------------------------------+
|
+-----------------------+-------------------------------------------------+
|
||||||
| :class:`TextChannel` | :class:`~ext.commands.TextChannelConverter` |
|
| :class:`TextChannel` | :class:`~ext.commands.TextChannelConverter` |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user