Skip to content

Errors and replies ​

success() and error() ​

Most commands end by telling someone it worked or it didn't. Ruby has two helpers so every command does it the same way:

python
from ruby.utils import error, success

await success(ctx)                          # ✅
await success(ctx, "Saved your birthday!")  # ✅ + a green embed
await error(ctx)                            # ❌
await error(ctx, "That isn't a real date.") # ❌ + a red embed

How they look depends on how the command was used:

Prefix command (r!wave)Slash command (/wave)
No messageReacts ✅ / ❌ to the commandReplies "✅" / "❌"
With a messageReacts and replies with the messageReplies with the message
No message, silent_on_slash=TrueReacts ✅ / ❌Says nothing (no "The application did not respond")

Messages are coloured embeds by default. Set embeds: false in the config for plain ✅ | message text instead.

Small things they handle for you:

  • If the reaction can't be added (message deleted, no permission, the bot is blocked), they reply instead, so the result isn't lost.
  • If the command message has been deleted, the reply is still sent, just without the "replying to" link.
  • The message can be a string key or plain text.

silent_on_slash ​

Use it when the command sends its own output and the ✅ is only a receipt for prefix users:

python
await success(ctx, silent_on_slash=True)  # ✅ on r!help, nothing extra on /help
await ctx.reply(embed=help_embed)

When a command fails ​

You don't need try/except around every command. Ruby has an error handler for prefix, hybrid and plain slash commands. It replies to the user and logs what the bot owner needs to know:

What went wrongUser seesLogged
On cooldownCOMMAND_ON_COOLDOWN, with a "try again in…" timestamp
commands.is_owner() failedNOT_OWNERwarning: who tried, and where
No such commandCOMMAND_NOT_FOUNDwarning
User is missing permissionsCOMMAND_MISSING_PERMISSION(S)
Bot is missing permissionsCOMMAND_BOT_MISSING_PERMISSION(S)
Missing argumente.g. "Member is a required argument that is missing."
Bad argument, failed check, disabled command, max concurrencydiscord.py's message, e.g. "Member "bob" not found."
An exception in your codeUNKNOWN_ERRORerror, with the exception
Anything elseUNKNOWN_COMMAND_ERRORerror

The user always gets a short message, and the details go to the log, not the chat.

Custom checks

Raise commands.CheckFailure("message") from a check, and that message is what the user sees.

Stopping a command early ​

The usual way is to reply and return:

python
if await require_guild(ctx):
    return

Deep inside helper functions, where returning would mean passing a flag back up through every caller, you can raise ZeroDivisionError instead. Ruby treats it as "stop here, quietly": no error reply and nothing logged. Reply to the user before raising it.

python
async def charge(ctx: Context, amount: int) -> None:
    if balance < amount:
        await error(ctx, "You can't afford that.")
        raise ZeroDivisionError  # ends the command, nothing else happens

WARNING

Only use this deliberately. A real ZeroDivisionError (an actual x / 0 bug) is hidden in the same way. It won't show up in the logs.