A Discord bot that monitors public channels for trigger phrases and automatically responds by sending helpful information through direct messages (DMs), private threads, or public replies.
- 🔍 Smart Trigger Detection:
- Monitors messages for specific phrases
- Supports three matching types:
- Exact match (case-insensitive)
- Regex patterns with word boundaries
- Fuzzy matching for flexible detection
- ⏱️ Cooldown System:
- Prevents spam by limiting responses
- Default 24-hour cooldown per trigger/user
- Admins can reset cooldowns manually
- 📨 Intelligent Response Delivery:
- Primary: Attempts to send via DM
- Fallback 1: Creates a private thread
- Fallback 2: Replies in the public channel
- 🛠️ Slash Commands:
/trigger add
- Create new triggers/trigger remove
- Delete existing triggers/trigger list
- View all triggers/cooldown reset
- Reset user cooldowns/stats
- View usage statistics
- 📊 Performance Tracking:
- Monitors successful/failed deliveries
- Tracks DMs, threads, and public replies
- Reports statistics via command
- Node.js 16.9.0 or higher
- npm (comes with Node.js)
- A Discord account
- Permission to add bots to a Discord server
- Go to the Discord Developer Portal
- Click "New Application" and name your bot
- Go to the "Bot" section
- Click "Add Bot"
- Under "Privileged Gateway Intents", enable:
- Message Content Intent
- Server Members Intent
- Presence Intent
- Save your bot token (you'll need this later)
- Go to OAuth2 > URL Generator
- Select scopes:
bot
,applications.commands
- Select bot permissions:
- Send Messages
- Create Public Threads
- Create Private Threads
- Send Messages in Threads
- Manage Messages
- Read Message History
- Select scopes:
- Use the generated URL to invite the bot to your server
-
Clone this repository:
git clone [repository-url] cd messagebot
-
Install dependencies:
npm install
-
Create a
.env
file in the root directory:BOT_TOKEN=your_discord_bot_token GUILD_ID=your_discord_server_id CLIENT_ID=your_bot_client_id
BOT_TOKEN
: From the Bot section in Developer PortalGUILD_ID
: Right-click your server > Copy Server IDCLIENT_ID
: Your Application ID from General Information
-
Build the project:
npm run build
-
Deploy slash commands:
npm run deploy-commands
-
Start the bot:
npm start
For development, use:
npm run dev
Triggers are stored in triggers.json
. Example structure:
{
"triggers": [
{
"id": "help",
"pattern": "\\b(help|need help|how|where|what)\\b",
"type": "regex",
"response": "Hey there! 👋 Here's some help information..."
}
]
}
-
Exact: Matches the exact phrase (case-insensitive)
{ "type": "exact", "pattern": "hello" }
-
Regex: Uses regular expressions with word boundaries
{ "type": "regex", "pattern": "\\b(help|support)\\b" }
-
Fuzzy: Matches if all words in the pattern appear in the message
{ "type": "fuzzy", "pattern": "how install" }
- Add a trigger:
/trigger add id:welcome pattern:"welcome" type:exact response:"Welcome to the server!"
- Remove a trigger:
/trigger remove id:welcome
- List all triggers:
/trigger list
- Reset a user's cooldown:
/cooldown reset user:@username trigger_id:welcome
- Check bot performance:
/stats
-
Bot Not Responding
- Verify bot is online in Discord
- Check if all intents are enabled
- Ensure bot has correct permissions
- Verify trigger patterns are correct
-
Commands Not Working
- Run
npm run deploy-commands
again - Check if CLIENT_ID is correct in .env
- Verify bot has applications.commands scope
- Run
-
DMs Not Being Sent
- Check if users have DMs enabled
- Verify bot has permission to send DMs
- Look for errors in bot console
ISC