Skip to content

A Discord bot powered by Flollama AI that assists users with coding, science learning, writing, and general knowledge in a clear, respectful, and neutral manner.

License

Notifications You must be signed in to change notification settings

pratyush0898/flollama-discord-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฆ™ Flollama Discord Bot

A Discord bot powered by Flollama AI that assists users with coding, science learning, writing, and general knowledge in a clear, respectful, and neutral manner.

๐Ÿ“‹ About Flollama

  • Name: Flollama (a combination of "Flow" and Llama/Ollama)
  • Creator: Pratyush Kumar, a young developer from India
  • Base Model: Meta's Llama 3.2 language model with Ollama AI infrastructure
  • Purpose: To assist users with coding, science learning, writing, and general knowledge
  • Goal: Provide helpful and accurate responses while being transparent about origins and limitations

โœจ Features

  • ๐ŸŽฏ Smart Responses: Responds to mentions and replies
  • ๐Ÿ’ฌ Context Awareness: Maintains conversation history per channel
  • ๐Ÿ“š Multiple Topics: Coding, science, writing, general knowledge
  • ๐Ÿ”ง Error Handling: Graceful error handling with user-friendly messages
  • ๐Ÿ“ Message Splitting: Automatically handles long responses
  • ๐ŸŽจ Rich Embeds: Beautiful info and help commands
  • ๐Ÿงน History Management: Clear conversation history when needed

๐Ÿš€ Quick Start

Prerequisites

  • Node.js 18.0.0 or higher
  • A Discord account and server
  • Basic knowledge of Discord bots and JavaScript

1. Clone the Repository

git clone https://github.com/pratyush0898/flollama-discord-bot.git
cd flollama-discord-bot

2. Install Dependencies

npm install

3. Set Up Discord Bot

Step 1: Create Discord Application

  1. Go to Discord Developer Portal
  2. Click "New Application"
  3. Give your bot a name (e.g., "Flollama")
  4. Click "Create"

Step 2: Create Bot User

  1. Go to the "Bot" section in the left sidebar
  2. Click "Add Bot"
  3. Copy the bot token (you'll need this later)

Step 3: Configure Bot Settings

In the Bot section, make sure to enable:

  • โœ… Message Content Intent (Required!)
  • โœ… Server Members Intent (Optional)
  • โœ… Presence Intent (Optional)

Step 4: Set Bot Permissions

Go to the "OAuth2" โ†’ "URL Generator" section:

Scopes:

  • โœ… bot
  • โœ… applications.commands (for future slash commands)

Bot Permissions:

  • โœ… Send Messages (Required)
  • โœ… Read Messages (Required)
  • โœ… Read Message History (Required)
  • โœ… Use External Emojis (Optional)
  • โœ… Add Reactions (Optional)
  • โœ… Embed Links (Recommended)
  • โœ… Attach Files (Optional)
  • โœ… Mention Everyone (Optional, use carefully)

Minimum Required Permissions Integer: 274877906944

4. Environment Setup

Create a .env file in the project root:

# Discord Bot Token (Required)
DISCORD_TOKEN=your_discord_bot_token_here

# Optional: Custom settings
NODE_ENV=production

5. Run the Bot

Development Mode (with auto-restart):

npm run dev

Production Mode:

npm start

6. Invite Bot to Server

  1. Copy the generated URL from Discord Developer Portal
  2. Open the URL in your browser
  3. Select your server and authorize the bot

๐ŸŽฎ Usage

Basic Commands

Action Command Example
Chat Mention the bot @Flollama Hello! How are you?
Reply Reply to bot's message Just reply to any bot message
Get Info Mention + "info" @Flollama info
Get Help Mention + "help" @Flollama help
Clear History Mention + "clear" @Flollama clear

Example Interactions

User: @Flollama Can you help me debug this Python code?

Flollama: I'd be happy to help you debug your Python code! Please share 
the code you're having trouble with, and let me know what error messages 
or unexpected behavior you're experiencing...
User: @Flollama Explain quantum computing simply

Flollama: Quantum computing is like having a super-powered calculator 
that can explore many possible solutions simultaneously...

๐Ÿ”ง Configuration

Environment Variables

Variable Required Description Default
DISCORD_TOKEN โœ… Yes Your Discord bot token None
NODE_ENV โŒ No Environment mode development

Bot Settings

You can modify these settings in index.js:

const MAX_HISTORY = 10; // Conversation history per channel
const MAX_MESSAGE_LENGTH = 2000; // Discord's character limit

๐Ÿ“Š API Information

The bot uses the Flollama API endpoint:

  • URL: https://flollama.in/api/chat
  • Method: POST
  • Content-Type: application/json
  • Streaming: Yes (handled automatically)

API Request Format

{
  "messages": [
    {
      "role": "user",
      "content": "Hello, how are you?"
    }
  ]
}

๐Ÿ› ๏ธ Development

Project Structure

flollama-discord-bot/
โ”œโ”€โ”€ index.js          # Main bot file
โ”œโ”€โ”€ package.json      # Dependencies and scripts
โ”œโ”€โ”€ README.md         # This file
โ”œโ”€โ”€ .env              # Environment variables (create this)
โ”œโ”€โ”€ .gitignore        # Git ignore file
โ””โ”€โ”€ node_modules/     # Dependencies (auto-generated)

Scripts

  • npm start - Run the bot in production mode
  • npm run dev - Run the bot in development mode with auto-restart

Adding New Features

  1. Add a new command:
if (isMentioned && message.content.toLowerCase().includes('your-command')) {
  // Your command logic here
  return message.reply('Response');
}
  1. Modify API calls:
// Edit the callFlollamaAPI function
async function callFlollamaAPI(messages) {
  // Your modifications here
}

๐Ÿšจ Troubleshooting

Common Issues

  1. Bot doesn't respond to mentions

    • โœ… Check if Message Content Intent is enabled
    • โœ… Verify bot has "Send Messages" permission
    • โœ… Make sure bot is online (check Discord)
  2. "Missing Permissions" error

    • โœ… Re-invite bot with correct permissions
    • โœ… Check channel-specific permissions
  3. API timeout errors

    • โœ… Check your internet connection
    • โœ… Verify Flollama API is accessible
    • โœ… Try again after a few minutes
  4. Bot appears offline

    • โœ… Check console for error messages
    • โœ… Verify DISCORD_TOKEN is correct
    • โœ… Restart the bot

Debug Mode

Run with debug information:

NODE_ENV=development npm start

Logs

The bot provides detailed console logs:

  • ๐Ÿš€ Startup messages
  • ๐Ÿ“จ Message processing
  • โœ… Successful responses
  • โŒ Error messages
  • โš ๏ธ Warnings

๐Ÿ” Security

Best Practices

  1. Never share your bot token
  2. Use environment variables for secrets
  3. Regularly rotate your bot token
  4. Limit bot permissions to minimum required
  5. Monitor bot usage and logs

Token Security

# Add .env to .gitignore
echo ".env" >> .gitignore

# Never commit tokens to version control
git add .gitignore
git commit -m "Add .gitignore for environment variables"

๐Ÿš€ Deployment

Heroku Deployment

  1. Create Heroku app:
heroku create your-flollama-bot
  1. Set environment variables:
heroku config:set DISCORD_TOKEN=your_token_here
  1. Deploy:
git push heroku main

Railway Deployment

  1. Connect your GitHub repo to Railway
  2. Set environment variables in Railway dashboard
  3. Deploy automatically on git push

VPS/Server Deployment

  1. Install PM2 for process management:
npm install -g pm2
  1. Start bot with PM2:
pm2 start index.js --name "flollama-bot"
pm2 startup
pm2 save

๐Ÿ“ˆ Monitoring

Health Checks

The bot logs important events:

  • Bot startup and login
  • Message processing
  • API calls and responses
  • Errors and warnings

Performance Metrics

  • Response time to messages
  • API call success/failure rates
  • Memory usage
  • Number of active servers

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Pratyush Kumar - Creator of Flollama
  • Meta - Llama 3.2 language model
  • Ollama - AI infrastructure
  • Discord.js - Discord API wrapper

๐Ÿ“ž Support


๐ŸŽ‰ Ready to Get Started?

  1. Follow the setup instructions above
  2. Invite your bot to a Discord server
  3. Mention the bot and start chatting!

Happy coding with Flollama! ๐Ÿฆ™โœจ

About

A Discord bot powered by Flollama AI that assists users with coding, science learning, writing, and general knowledge in a clear, respectful, and neutral manner.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published