diff options
author | 2022-07-23 14:25:45 +0100 | |
---|---|---|
committer | 2022-07-23 14:25:45 +0100 | |
commit | 4e43f3c4705c8c26cb2b4c5ca01e1f2885766c80 (patch) | |
tree | 5ed7624cdb6b4677c1a5b83cd0bff69f70c744c4 /botcore | |
parent | Reformat docstring to use Google's style & raise error instead of returning None (diff) |
Raise error when referenced message has no content
Diffstat (limited to 'botcore')
-rw-r--r-- | botcore/utils/commands.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/botcore/utils/commands.py b/botcore/utils/commands.py index a99b3852..7afd8137 100644 --- a/botcore/utils/commands.py +++ b/botcore/utils/commands.py @@ -14,7 +14,7 @@ async def clean_text_or_reply(ctx: Context, text: Optional[str] = None) -> str: Raises: :exc:`discord.ext.commands.BadArgument` - `text` wasn't provided and there's no reply message. + `text` wasn't provided and there's no reply message / reply message content. Returns: The cleaned version of `text`, if given, else replied message. @@ -28,7 +28,11 @@ async def clean_text_or_reply(ctx: Context, text: Optional[str] = None) -> str: (replied_message := getattr(ctx.message.reference, "resolved", None)) # message has a cached reference and isinstance(replied_message, Message) # referenced message hasn't been deleted ): - return await clean_content_converter.convert(ctx, ctx.message.reference.resolved.content) + if not (content := ctx.message.reference.resolved.content): + # The referenced message doesn't have a content (e.g. embed/image), so raise error + raise BadArgument("The referenced message doesn't have a text content.") + + return await clean_content_converter.convert(ctx, content) # No text provided, and either no message was referenced or we can't access the content raise BadArgument("Couldn't find text to clean. Provide a string or reply to a message to use its content.") |