A feature-rich Discord bot designed for entertainment and utility, with AI-powered article summarization, interactive reactions, and fun random behaviors. Built with Discord.js v14 and modern async/await patterns.
- Auto-Summarization: Automatically detects and summarizes articles from links using GPT
- Interactive Reactions: Original poster can delete summaries with โ reaction
- Multiple Content Sources: Supports various article formats and websites
/ping- Test bot responsiveness/ask- AI-powered Q&A using OpenAI/summarize- Manual article summarization/slotmachine- Fun gambling game/wfdropinfo- Warframe drop information/ttsreply- Text-to-speech responses
- Probabilistic Message Deletion: Random chance to delete messages
- Random Reactions: Adds surprise reactions to messages
- Random AI Responses: Contextual AI-generated replies
- Message History Tracking: Learns from conversation patterns
- SQLite database for user activity tracking
- Message count monitoring
- User interaction statistics
- Persistent data storage
- Custom embed messages
- Button interactions
- Reaction collectors
- Canvas-based image generation
- Node.js 18+
- Docker (optional)
- Discord Bot Token
- OpenAI API Key
- Clone the repository:
git clone <repository-url>
cd Randomfunbot- Install dependencies:
npm install- Configure environment variables:
Create a
.envfile in the root directory:
token=YOUR_DISCORD_BOT_TOKEN
gptApiKey=YOUR_OPENAI_API_KEY
clientId=YOUR_BOT_CLIENT_ID
guildId=YOUR_GUILD_ID
linkChannelId=YOUR_LINK_CHANNEL_ID
mainChannelId=YOUR_MAIN_CHANNEL_ID
me=YOUR_USER_ID- Set up Discord Bot:
- Go to Discord Developer Portal
- Create a new application and bot
- Copy the bot token to your
.envfile - Enable the following bot permissions:
- Send Messages
- Manage Messages
- Add Reactions
- Read Message History
- Use Slash Commands
# Build the image
docker build -t randomfunbot .
# Run the container
docker run -d --name randomfunbot --env-file .env randomfunbot# Start the bot
npm start
# Or run with nodemon for development
npm run devYour Discord bot needs these permissions:
- โ Send Messages
- โ Manage Messages
- โ Add Reactions
- โ Read Message History
- โ Use Slash Commands
- โ Embed Links
- โ Attach Files
| Variable | Description | Required |
|---|---|---|
token |
Discord bot token | โ |
gptApiKey |
OpenAI API key for AI features | โ |
clientId |
Discord application client ID | โ |
guildId |
Discord server ID | โ |
linkChannelId |
Channel ID for link processing | โ |
mainChannelId |
Main channel ID | โ |
me |
Your Discord user ID | โ |
src/
โโโ client.js # Discord client setup
โโโ index.js # Bot entry point
โโโ handlers/
โ โโโ commandHandler/ # Slash commands
โ โ โโโ commands/ # Individual command files
โ โโโ messageHandlers/ # Message event handlers
โ โ โโโ linkHandler.js # Link processing & summarization
โ โ โโโ randomResponseHandler.js
โ โ โโโ dmHandler.js
โ โโโ gptResponseHandler/ # AI response logic
โ โโโ articleSummaryHandler/ # Web scraping & content extraction
โ โโโ buttonHandler/ # Button interactions
โโโ utils/ # Utility functions
โโโ webpage.png # Generated screenshots
database/
โโโ botDB.db # SQLite database
โโโ dbBuild.js # Database initialization
config/
โโโ config.json # Bot configuration
- Create a new file in
src/handlers/commandHandler/commands/ - Export a command object with
dataandexecuteproperties - The command will be automatically loaded
Example:
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('example')
.setDescription('An example command'),
async execute(interaction) {
await interaction.reply('Hello World!');
},
};The bot uses SQLite for data persistence. Database utilities are in database/databaseUtils/:
insertDB.js- Insert operationsupdateDB.js- Update operations
- Uses OpenAI GPT for article summarization and Q&A
- Handles rate limiting and error recovery
- Supports both chat completions and legacy models
The bot logs important events:
- Startup and shutdown
- Command executions
- Error handling
- Database operations
- Article processing
- Uses Puppeteer with stealth plugin for web scraping
- Implements connection pooling for database
- Graceful error handling for external APIs
- Memory-efficient reaction collectors
- โ Environment variables for sensitive data
- โ Input validation and sanitization
- โ Rate limiting protection
- โ Error boundaries and logging
- โ Graceful process shutdown
- โ Docker containerization support
Bot doesn't respond to commands:
- Check bot permissions in Discord server
- Verify bot token is correct
- Ensure bot is online and connected
Article summarization fails:
- Check OpenAI API key and credits
- Verify internet connectivity
- Review console logs for Puppeteer errors
Database errors:
- Ensure write permissions for database file
- Check SQLite installation
- Review database schema
Puppeteer/Chrome issues:
- Install missing dependencies:
apt-get install -y chromium-browser - Use
--no-sandboxflag in Docker - Check available memory
Set NODE_ENV=development for verbose logging.
This project is licensed under the ISC License.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request