⚑ RED-DISCORDBOT DEVELOPER QUICK REFERENCE ⚑

⚑ RED-DISCORDBOT DEVELOPER QUICK REFERENCE ⚑ #

Instant Access Cheat Sheet


πŸš€ INSTANT SETUP #

pip install Red-DiscordBot
redbot-setup                # Interactive setup
redbot <instance_name>      # Launch bot

πŸ”‘ ESSENTIAL IMPORTS #

from redbot.core import commands, Config, bank
from redbot.core.bot import Red
from redbot.core.utils.chat_formatting import box, pagify
from discord.ext import commands as dpy_commands

🧩 COG TEMPLATE #

import discord
from redbot.core import commands, Config

class MyCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.config = Config.get_conf(self, identifier=1234567890)
        default_guild = {"setting": "default_value"}
        self.config.register_guild(**default_guild)
    
    @commands.command()
    async def mycommand(self, ctx):
        """Command description"""
        await ctx.send("Response")

πŸ“Š CONFIG PATTERNS #

# Basic config setup
self.config = Config.get_conf(self, identifier=12345)
self.config.register_global(setting=default)
self.config.register_guild(guild_setting=default)
self.config.register_user(user_setting=default)

# Get/Set values
value = await self.config.setting()
await self.config.setting.set(new_value)

# Nested data
async with self.config.guild(guild).nested() as data:
    data["key"] = "value"

πŸ›‘οΈ PERMISSION DECORATORS #

@commands.admin()           # Admin only
@commands.mod()             # Moderator+
@commands.guild_only()      # Guild only
@commands.bot_has_permissions(manage_roles=True)
@commands.has_permissions(kick_members=True)

πŸ’° ECONOMY INTEGRATION #

from redbot.core import bank

# Check balance
balance = await bank.get_balance(user)

# Transfer credits
await bank.deposit_credits(user, amount)
await bank.withdraw_credits(user, amount)

# Cost decorator
@bank.cost(100)
async def expensive_command(self, ctx):
    pass

🎯 COMMAND TYPES #

# Basic command
@commands.command()
async def basic(self, ctx, arg):
    pass

# Group command
@commands.group()
async def group(self, ctx):
    pass

@group.command()
async def subcommand(self, ctx):
    pass

# Hybrid command (slash + prefix)
@commands.hybrid_command()
async def hybrid(self, ctx, arg: str):
    pass

πŸ”§ CONVERTERS #

@commands.command()
async def cmd(self, ctx, user: discord.Member, amount: int):
    pass

# Custom converter
class MyConverter(commands.Converter):
    async def convert(self, ctx, argument):
        return processed_argument

πŸ“ EMBED PATTERNS #

embed = discord.Embed(
    title="Title",
    description="Description",
    color=await ctx.embed_color()
)
embed.add_field(name="Field", value="Value", inline=False)
await ctx.send(embed=embed)

🎨 FORMATTING UTILITIES #

from redbot.core.utils.chat_formatting import box, pagify, humanize_list

# Code blocks
await ctx.send(box("code", lang="python"))

# Pagination
for page in pagify(long_text):
    await ctx.send(page)

# Lists
await ctx.send(humanize_list(["item1", "item2", "item3"]))

πŸ”„ EVENT HANDLING #

@commands.Cog.listener()
async def on_message(self, message):
    if message.author.bot:
        return
    # Handle message

@commands.Cog.listener()
async def on_member_join(self, member):
    # Handle new member
    pass

πŸ—‚οΈ DATA SCOPES #

  • GLOBAL - Bot-wide settings
  • GUILD - Per-server settings
  • CHANNEL - Per-channel settings
  • USER - Per-user settings (global)
  • MEMBER - Per-member settings (guild-specific)
  • ROLE - Per-role settings
  • CUSTOM - Custom identifier

πŸ” ERROR HANDLING #

@commands.command()
async def cmd(self, ctx):
    try:
        # Command logic
        pass
    except commands.BadArgument:
        await ctx.send("Invalid argument!")
    except Exception as e:
        await ctx.send(f"Error: {e}")

πŸ“¦ COG LIFECYCLE #

async def cog_load(self):
    """Called when cog is loaded"""
    pass

async def cog_unload(self):
    """Called when cog is unloaded"""
    pass

def cog_check(self, ctx):
    """Check for all commands in cog"""
    return True

🎡 AUDIO COG BASICS #

from redbot.cogs.audio.core.abc import MixinMeta

class AudioCog(MixinMeta):
    def __init__(self, bot):
        self.bot = bot
        super().__init__()

πŸ”§ DEBUGGING TIPS #

  • Use [p]load dev for development tools
  • [p]reload cog_name to reload cog during development
  • Check logs in data directory
  • Use print() statements for quick debugging
  • await ctx.tick() for success confirmation

πŸ“š KEY DOCUMENTATION PATHS #

  • Official Docs: docs.discord.red
  • API Reference: redbot.readthedocs.io
  • Cog Creation Guide: docs.discord.red/en/stable/guide_cog_creation.html
  • Config Tutorial: docs.discord.red/en/stable/framework_config.html

🚨 COMMON GOTCHAS #

  • Always use ctx.send() instead of channel.send() when possible
  • Register config defaults before first access
  • Use guild_only() for guild-specific commands
  • Check permissions before attempting Discord actions
  • Use async context managers for config modifications

⚑ Keep this reference handy for rapid Red-DiscordBot development