Skip to content
Back to skills

Add Cog

ASecurity

Step-by-step guide to add a new discord.py Cog to the framework

  • 59 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 22, 2026
ai-agentspythonbashapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned September 22, 2026

npx -y skills add ebibibi/ebi-agent-chat-relay --skill add-cog --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Add Cog?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Add Cog
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ebibibi-add-cog/badge)](https://www.skillsdirectory.com/skills/ebibibi-add-cog)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: add-cog
description: Step-by-step guide to add a new discord.py Cog to the framework
---

# Add Cog — Scaffold a New Discord.py Cog

## When to Activate

- Adding new Discord bot functionality
- Creating a new slash command or event handler
- When asked to "add a cog", "create a command", or "add a feature"

## Steps

### 1. Create the Cog File

Create `claude_discord/cogs/your_cog.py`:

```python
"""Short description of what this Cog does."""

from __future__ import annotations

import logging

import discord
from discord import app_commands
from discord.ext import commands

logger = logging.getLogger(__name__)


class YourCog(commands.Cog):
    """Docstring explaining the Cog's purpose."""

    def __init__(
        self,
        bot: commands.Bot,
        # Add dependencies as constructor params (dependency injection)
    ) -> None:
        self.bot = bot

    # Add commands and listeners here
```

### 2. If It Runs Claude CLI

Use the shared helper — **never duplicate the streaming logic**:

```python
from ._run_helper import run_claude_in_thread

# In your command handler:
runner = self.runner.clone()  # Always clone for concurrent safety
await run_claude_in_thread(
    thread=thread,
    runner=runner,
    repo=self.repo,
    prompt=user_input,
    session_id=existing_session_id,
)
```

### 3. Export from Package

Add to `claude_discord/cogs/__init__.py`:

```python
from .your_cog import YourCog
```

Add to `claude_discord/__init__.py`:

```python
from .cogs.your_cog import YourCog
# And add "YourCog" to __all__
```

### 4. Write Tests

Create `tests/test_your_cog.py`:

- Test command validation (invalid inputs, edge cases)
- Test authorization checks
- Mock Discord objects (`discord.Interaction`, `discord.TextChannel`, etc.)
- Test error handling paths

### 5. Verify

Run the verify skill to ensure everything passes:

```bash
uv run ruff check claude_discord/
uv run ruff format claude_discord/
uv run pytest tests/ -v --cov=claude_discord
```

## Conventions

- **Type hints**: Required on all function signatures
- **`from __future__ import annotations`**: Required in every file
- **Logging**: Use `logger = logging.getLogger(__name__)`, never `print()`
- **Authorization**: If the Cog accepts user commands, check `_is_authorized(user_id)`
- **Input validation**: Validate all user-provided strings with regex before passing to subprocess
- **Error handling**: Use `contextlib.suppress(discord.HTTPException)` for non-critical Discord API calls

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.