Add role selection system with select menus
All checks were successful
Auto Build and Push Docker Image / build (push) Successful in 7s

This commit is contained in:
2026-04-02 10:55:43 +00:00
parent f90f0cb7ab
commit ad988c9333
5 changed files with 624 additions and 3 deletions

View File

@@ -16,7 +16,8 @@ The bot uses a **Modular Command & Event Loading** pattern with **ESM (ECMAScrip
7. **Auto-Response System:** Trigger word detection for automatic replies.
8. **Welcome/Goodbye System:** Guild member add/remove events with customizable messages.
9. **Logging System:** Configurable event logging (messages, roles, moderation, etc.).
10. **Grouped Commands:** Admin/Owner/Trigger/Timer commands grouped under subcommands.
10. **Role Selection System:** Self-service role assignment via select menus.
11. **Grouped Commands:** Admin/Owner/Trigger/Timer commands grouped under subcommands.
## 📁 Project Structure
@@ -30,6 +31,7 @@ pixelpoebel/
│ │ ├── ping.ts
│ │ ├── help.ts
│ │ ├── twitch.ts
│ │ ├── rolesetup.ts # Self-service role selection
│ │ ├── trigger.ts # Auto-responses
│ │ ├── timer.ts # Reminders
│ │ ├── welcome.ts # Welcome/Goodbye messages
@@ -165,6 +167,30 @@ CREATE TABLE reminders (
target_time DATETIME,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- role_categories
CREATE TABLE role_categories (
id INTEGER PRIMARY KEY AUTOINCREMENT,
guild_id TEXT NOT NULL,
channel_id TEXT NOT NULL,
message_id TEXT NOT NULL,
category_name TEXT NOT NULL,
max_roles INTEGER DEFAULT 0,
exclusive BOOLEAN DEFAULT 0,
remove_on_delete BOOLEAN DEFAULT 0,
UNIQUE(guild_id, category_name)
);
-- role_options
CREATE TABLE role_options (
id INTEGER PRIMARY KEY AUTOINCREMENT,
category_id INTEGER NOT NULL,
label TEXT NOT NULL,
emoji TEXT,
role_id TEXT NOT NULL,
UNIQUE(category_id, role_id),
FOREIGN KEY (category_id) REFERENCES role_categories(id) ON DELETE CASCADE
);
```
### 3. Key Components
@@ -392,6 +418,42 @@ await channel.bulkDelete(filtered, true);
**Logging:** Purge actions are logged to the moderation log channel with event type `messages`.
### 12. Role Selection System
**Overview:** Self-service role assignment via Discord Select Menus. Users can choose roles from a dropdown message without needing admin intervention.
**Admin Commands:**
```typescript
/rolesetup create <#channel> <category_name> // Create new role selection message
/rolesetup add <kategorie> <@rolle> [emoji] // Add role option
/rolesetup edit <kategorie> <@rolle> [new_emoji] // Change emoji
/rolesetup remove <kategorie> <@rolle> // Remove role option
/rolesetup delete <kategorie> // Delete entire category
/rolesetup config <kategorie> max:1 exclusive:true // Configure settings
/rolesetup list // Show all configurations
```
**Config Options:**
| Option | Default | Description |
|--------|---------|-------------|
| `max_roles` | 0 (unlimited) | Maximum roles a user can select from this category |
| `exclusive` | false | If true, selecting a role removes other roles in this category |
| `remove_on_delete` | false | Remove role from users when option is deleted |
**User Interaction:**
- User clicks on Select Menu dropdown
- Role is added/removed based on config
- Ephemeral confirmation message appears (auto-hides after 60s)
**Database Schema:**
- `role_categories`: Stores category settings (channel, message_id, config)
- `role_options`: Stores individual role options with labels and emojis
- CASCADE DELETE removes options when category is deleted
**Role Validation:**
- On bot startup, validates that all stored role IDs still exist in Discord
- Missing roles are removed from database (and optionally from users)
## 🚀 Build & Deploy
```bash
@@ -425,6 +487,7 @@ docker-compose up -d --build
| `/ping` | | Public |
| `/help` | | Public |
| `/twitch` | online, add, remove, list, listall, help | Public/Admin |
| `/rolesetup` | create, add, edit, remove, delete, config, list | Admin |
| `/trigger` | add, remove, list, help | Public/Admin |
| `/timer` | add, remove, list, listall, help | Public/Admin |
| `/welcome` | setchannel, add, remove, list, help | Admin |