A Discord.js bot with quote management, reaction tracking, and Prisma ORM. Handles slash commands, context menus, and database persistence patterns for Discord bots.
You are working with **Zipbot**, a Discord bot built with Discord.js v13 and Prisma ORM. This skill provides context-aware guidance for developing, debugging, and extending this bot.
The main file initializes the Discord client and registers three event handlers:
1. **guildCreate** - Creates a Guild database record when the bot joins a server
2. **messageCreate** - Auto-triggers the "react" command when messages contain "unzip"
3. **interactionCreate** - Routes slash commands and context menu interactions to their handlers
Commands are stored in a `Collection<string, Command<T>>` where `T` is `Message`, `CommandInteraction`, or `ContextMenuInteraction`.
All commands implement the `Command<T>` interface defined in `src/types.d.ts`:
```typescript
interface Command<T> {
data: any; // Command metadata (name, description, type)
execute: (interaction: T) => Promise<void>;
}
```
**Message Commands** (`Command<Message>`)
**Slash Commands** (`Command<CommandInteraction>`)
**Context Menu Commands** (`Command<ContextMenuInteraction>`)
```
Guild (1:many) → Channel, Invocation, Quote
User (1:many) → Invocation, Quote (as author or submitter)
```
**Models:**
To avoid duplicate key errors when encountering users or channels for the first time, all commands use Prisma's `connectOrCreate`:
```typescript
user: {
connectOrCreate: {
create: { id: author.id, name: author.username },
where: { id: author.id }
}
}
```
**Always use this pattern** when creating relations to `User` or `Channel` models.
```bash
npm run start:dev
npm run build
npm start
```
```bash
npm run prisma:generate
npm run prisma:migrate
npx prisma migrate dev
npx prisma studio
```
```bash
docker-compose up
```
1. Create a file in `src/commands/` implementing `Command<CommandInteraction>`
2. Define `data` using Discord.js SlashCommandBuilder
3. Implement `execute()` with database logic using `connectOrCreate` pattern
4. Export and register in `src/index.ts`
1. Update `prisma/schema.prisma`
2. Run `npx prisma migrate dev --name <migration-name>`
3. Run `npm run prisma:generate` to update Prisma client types
```typescript
// determineCacheState() in leaderboard.ts
// - Caches results for 30 minutes
// - Stores lastFetched timestamp
// - Returns cached data if still valid
```
Create `.env` based on `.env.example`:
```env
TOKEN=your_discord_bot_token
DATABASE_URL=postgresql://user:password@localhost:5432/zipbot
NODE_ENV=development # Shows Prisma query logs
```
| File | Purpose |
|------|---------|
| `src/index.ts` | Entry point, event handlers, command registration |
| `src/prisma.ts` | Singleton PrismaClient with conditional logging |
| `src/constants.ts` | REACTIONS array, embed colors, leaderboard emojis |
| `src/types.d.ts` | Command interface and type definitions |
| `prisma/schema.prisma` | Database schema |
1. **Always use `connectOrCreate`** for User and Channel relations
2. **Validate input** before database writes (see highlight.ts checks)
3. **Handle errors gracefully** - reply with user-friendly messages
4. **Use embed footers** to show metadata (invocation counts, timestamps)
5. **Cache expensive queries** when possible (leaderboard pattern)
6. **Test migrations** in development before applying to production
Add URLs to the `REACTIONS` array in `src/constants.ts`.
Run `npx prisma studio` to inspect records visually.
Modify the `Intents` array in `src/index.ts` if adding features requiring new permissions.
Update the `30 * 60 * 1000` value in `leaderboard.ts` (currently 30 minutes).
---
When making changes to this bot, always consider:
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/zipbot-discord-bot-development/raw