RubyBot
from ruby import RubyBot, runRubyBot is a discord.ext.commands.Bot subclass. You don't normally create it yourself: python -m ruby calls run(), which makes one and logs in with TOKEN from the environment. Cogs get it as self.bot.
Attributes
| Attribute | Type | What it is |
|---|---|---|
cfg | Config | The loaded config.yaml. |
db | AsyncDatabase | The MongoDB database named after cfg.name. |
mongo | AsyncMongoClient | The client behind db, connected to MONGO_URI. |
server | Server | Shortcut for cfg.server: id, name, invite, channels. |
prefix | str | The configured prefix, as written. |
name | str | cfg.name |
friendly_name | str | cfg.friendly_name |
logger | logging.Logger | Writes to bot.log. See Logging. |
utils | module | ruby.utils, for cogs that would rather not import it. |
status_task | tasks.Loop | Rotates cfg.statuses every cfg.status_interval seconds. Started on the first on_ready. |
Everything from commands.Bot is there too: get_channel, is_owner, tree, wait_until_ready, and so on.
Methods
await bot.log(level, msg)
Logs msg to bot.log and, if level is at least cfg.log_level and a log channel is set, to the log channel as an embed.
await self.bot.log(logging.WARNING, "Couldn't find the bump channel")await bot.discord_log(level, msg)
Just the Discord half of log(). Rarely needed on its own.
await bot.load_cogs()
Loads every cogs/*.py that doesn't start with _, logging failures instead of raising. Called for you from setup_hook.
Intents
RubyBot uses discord.Intents.default() plus message_content and members. Both are privileged and must be enabled in the Developer Portal.
Event handlers Ruby defines
If a cog wants to react to these events, add a @commands.Cog.listener(). Overriding them on the bot replaces Ruby's handling.
| Event | What Ruby does |
|---|---|
setup_hook | Loads cogs. |
on_ready | Logs the login, starts the status loop (once, even after reconnects) and syncs the slash commands with Discord. |
on_command_completion | Logs the command at DEBUG. |
on_command_error | The friendly error replies: see Errors and replies. |
tree.on_error | Sends plain slash command errors to on_command_error, so they get the same handling. |