Nebula is an advanced AI-powered Discord bot built with Python and discord.py, featuring conversational AI capabilities, memory management, and comprehensive admin tools. Now fully migrated to Slash Commands for a modern, seamless experience.
- Natural language processing using gemini-3.1-flash-lite
- High efficiency with near-zero hallucination rates
- Context-aware responses that remember previous conversations
- Addresses users by their display names for personal engagement
- Handles replies to messages intelligently
- SQLite database for conversation history
- 400,000 token memory capacity
- Automatic memory reset when limit is reached
- Tracks individual users while maintaining shared conversation context
- Admin commands for monitoring and resetting memory
An elegant rate-limiting system designed to prevent spam and optimize hosting costs:
- Starting Balance: Every user starts with 10 coins per guild.
- Consumption:
- 1 coin per AI message response.
- 2 coins per web search.
- Automatic Reset: Balance resets back to 10 (does not stack) every 8 hours.
- Transparency: Users can check their budget at any time.
- Admin Control: Administrators can manually grant or set coin balances for users.
- Google Custom Search API integration
- Available to all users (costs 2 Nebula Coins)
- Returns formatted search results with links
- Kick User: Remove members from the server via AI request
- Ban User: Permanently ban members via AI request
- Create Channel: Create text or voice channels in specified categories via AI request
- User Activity Check: View detailed user activity statistics
- Admin Logs: Track all moderation actions via
/admin_logs - Resource Control: Manage server resource consumption via the Coin System
- Automatic message splitting for long responses (>2000 characters)
- Image attachment detection
- Reply context awareness
- Comprehensive logging system
- Full Slash Command support
- Python 3.9 or higher
- Discord Bot Token
- OpenAI-compatible API Key (e.g., Google AI Studio, OpenAI, Liara.ir)
- Google Custom Search API Key (optional, for search functionality)
git clone https://github.com/sinamsv/NebulaBot
cd NebulaBotpip install -r requirements.txt- Copy
.env.sampleto.env:
cp .env.sample .env- Edit
.envand fill in your credentials:
DISCORD_TOKEN=your_discord_bot_token_here
OPENAI_API_KEY=your_api_key_here
OPENAI_BASE_URL= # Optional: e.g., https://generativelanguage.googleapis.com/v1beta/openai/
AI_MODEL=google/gemini-3.1-flash-lite
GOOGLE_SEARCH_API_KEY=your_google_search_api_key_here
GOOGLE_SEARCH_ENGINE_ID=your_search_engine_id_here- Go to Discord Developer Portal
- Create a new application
- Go to the "Bot" section
- Click "Reset Token" and copy your bot token
- Enable these Privileged Gateway Intents:
- Server Members Intent
- Message Content Intent
- Go to Google AI Studio
- Create a new API key
- Copy the key into
OPENAI_API_KEYin.env - Set
OPENAI_BASE_URLtohttps://generativelanguage.googleapis.com/v1beta/openai/
- Get API Key: Google Cloud Console
- Get Search Engine ID: Programmable Search Engine
Edit system.txt to customize Nebula's personality and behavior.
python bot.pySimply mention the bot in any message to start a conversation:
@Nebula what's the weather like?
@Nebula can you help me understand this concept?
Nebula also understands context when you mention it in a reply:
[Reply to a message] @Nebula can you explain this?
Note: Each response costs 1 Nebula Coin.
Ask Nebula to search for information:
@Nebula search for the latest AI news
Or use the direct slash command:
/search query: Python best practices
Note: Each search costs 2 Nebula Coins.
/coin: Show your current Nebula Coin balance and time until reset./search query:<text>: Perform a web search using Google Custom Search.
/add_coin member:@user amount:<number> mode:<add|set>: Modify a user's Nebula Coin balance./admin_logs limit:<number>: View recent administrative action logs./memory_stats: Show memory usage statistics for the current channel./reset_memory: Clear conversation memory for the current channel.
You can perform moderation tasks by simply asking Nebula while mentioning it:
@Nebula kick @username for spamming
@Nebula ban @username for violating rules
@Nebula create a text channel called "general-chat" in the "Community" category
@Nebula check activity for @username
nebula-bot/
βββ bot.py # Main bot file
βββ database.py # Database management
βββ system.txt # AI system prompt
βββ requirements.txt # Python dependencies
βββ .env.sample # Environment variables template
βββ cogs/
β βββ ai_handler.py # AI message processing
β βββ admin_tools.py # Admin moderation tools
β βββ search_tool.py # Google Search integration
β βββ memory_manager.py # Memory and token management
β βββ coin_manager.py # Nebula Coin system
βββ nebula.db # SQLite database (created on first run)
Stores all conversation messages with token counts.
Tracks user information and activity statistics.
Tracks user coin balances and reset timestamps per guild.
Stores server-specific configuration.
Logs all administrative actions for audit purposes.
- Max Tokens: 400,000 tokens
- Auto-Reset: Automatically resets when limit is reached
- Token Counting: Uses tiktoken for accurate token counting
- Model: google/gemini-3.1-flash-lite (Recommended for efficiency and accuracy)
- Temperature: 0.7
- Max Tokens: 2000 per response
- Custom Base URL: Supports OpenAI-compatible APIs
- Max Message Length: 2000 characters (Discord limit)
- Auto-Split: Long messages are automatically split
- Reply Context: Includes replied-to messages in context
The bot needs the following Discord permissions:
- Read Messages/View Channels
- Send Messages
- Manage Messages
- Embed Links
- Read Message History
- Mention Everyone (for admin tools)
- Kick Members (for kick tool)
- Ban Members (for ban tool)
- Manage Channels (for create channel tool)
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.
MIT License
Enjoy using Nebula! π