aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Izan <[email protected]>2022-07-23 14:22:30 +0100
committerGravatar Izan <[email protected]>2022-07-23 14:22:30 +0100
commit85063ab4cd2ad6a7d6621645c049d0917affbfbe (patch)
treeeada2636c3404a8e228a1680399b2245c5edba7f
parentAdd commands.py to __init__.py (diff)
Reformat docstring to use Google's style & raise error instead of returning None
-rw-r--r--botcore/utils/commands.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/botcore/utils/commands.py b/botcore/utils/commands.py
index 2d380bef..a99b3852 100644
--- a/botcore/utils/commands.py
+++ b/botcore/utils/commands.py
@@ -1,11 +1,24 @@
from typing import Optional
from discord import Message
-from discord.ext.commands import Context, clean_content
+from discord.ext.commands import BadArgument, Context, clean_content
-async def clean_text_or_reply(ctx: Context, text: Optional[str] = None) -> Optional[str]:
- """Returns cleaned version of `text`, if given, else referenced message, if found, else `None`."""
+async def clean_text_or_reply(ctx: Context, text: Optional[str] = None) -> str:
+ """
+ Cleans a text argument or replied message's content.
+
+ Args:
+ ctx: The command's context
+ text: The provided text argument of the command (if given)
+
+ Raises:
+ :exc:`discord.ext.commands.BadArgument`
+ `text` wasn't provided and there's no reply message.
+
+ Returns:
+ The cleaned version of `text`, if given, else replied message.
+ """
clean_content_converter = clean_content(fix_channel_mentions=True)
if text:
@@ -18,4 +31,4 @@ async def clean_text_or_reply(ctx: Context, text: Optional[str] = None) -> Optio
return await clean_content_converter.convert(ctx, ctx.message.reference.resolved.content)
# No text provided, and either no message was referenced or we can't access the content
- return None
+ raise BadArgument("Couldn't find text to clean. Provide a string or reply to a message to use its content.")