A TypeScript Discord bot that supports multiple AI personalities and can use different LLM backends including LM Studio (local), OpenAI API, and Heroku Inference.
- π€ Multiple Bot Personalities: Support for multiple bot instances with different personalities (Poi, Moi, etc.)
- π Multiple AI Providers: Switch between LM Studio, OpenAI, and Heroku Inference
- β‘ Production Ready: Includes linting, type checking, and CI/CD with GitHub Actions
- π Heroku Deployment: Ready for cloud deployment with proper configuration
- π¬ Smart Conversation: Context-aware replies with typing delays and cooldowns
- Node.js 22.x
- Discord bot tokens (one for each personality)
- AI provider (LM Studio, OpenAI API key, or Heroku Inference)
- Clone the repository:
git clone <your-repo-url>
cd mybot
```markdown
2. Install dependencies:
```bash
npm install- Create a
.envfile with your configuration:
cp .env.example .env
# Edit .env with your tokens and settings- Build the project:
npm run build- Start the bot:
npm startCreate a .env file in the root directory:
# Discord Bot Tokens
POI_TOKEN=your_poi_bot_token_here
MOI_TOKEN=your_moi_bot_token_here
# General Settings
CHANNEL=#general
MODEL=your_model_name
INTERVAL=5
LEADER_NAME=YourName
# AI Provider (choose one: 'lmstudio', 'openai', or 'heroku')
AI_PROVIDER=lmstudio
# OpenAI Settings (if using OpenAI)
OPENAI_API_KEY=your_openai_api_key
# Heroku Inference Settings (if using Heroku Inference)
INFERENCE_KEY=your_inference_api_key
INFERENCE_MODEL_ID=your_model_id
INFERENCE_URL=https://your-inference-app.herokuapp.com-
Install and start LM Studio:
- Download from https://lmstudio.ai/
- Load your preferred model
- Start the local server
-
Verify LM Studio is running:
curl http://localhost:1234/v1/models- Set your
.env:
AI_PROVIDER=lmstudio- Run in development mode:
npm run dev2025-06-28 05:33:51 [INFO]
[LM STUDIO SERVER] Success! HTTP server listening on port 1234
2025-06-28 05:33:51 [INFO]
[LM STUDIO SERVER] Supported endpoints:
2025-06-28 05:33:51 [INFO]
[LM STUDIO SERVER] -> GET <http://localhost:1234/v1/models>
2025-06-28 05:33:51 [INFO]
[LM STUDIO SERVER] -> POST <http://localhost:1234/v1/chat/completions>
2025-06-28 05:33:51 [INFO]
[LM STUDIO SERVER] -> POST <http://localhost:1234/v1/completions>
2025-06-28 05:33:51 [INFO]
[LM STUDIO SERVER] -> POST <http://localhost:1234/v1/embeddings>
-
Install Heroku CLI:
- Download from https://devcenter.heroku.com/articles/heroku-cli
- Run
heroku login
-
Create a Heroku app:
heroku create your-bot-name- Create a Procfile in your project root:
echo "worker: npm start" > Procfile- Set environment variables on Heroku:
# Discord tokens
heroku config:set POI_TOKEN=your_poi_bot_token_here
heroku config:set MOI_TOKEN=your_moi_bot_token_here
# General settings
heroku config:set CHANNEL=#general
heroku config:set MODEL=your_model_name
heroku config:set INTERVAL=5
heroku config:set LEADER_NAME=YourName
# For OpenAI
heroku config:set AI_PROVIDER=openai
heroku config:set OPENAI_API_KEY=your_openai_api_key
# OR for Heroku Inference
heroku config:set AI_PROVIDER=heroku
heroku config:set INFERENCE_KEY=your_inference_api_key
heroku config:set INFERENCE_MODEL_ID=your_model_id
heroku config:set INFERENCE_URL=https://your-inference-app.herokuapp.com- Deploy to Heroku:
git add .
git commit -m "Deploy to Heroku"
git push heroku main- Scale the worker dyno:
heroku ps:scale worker=1- Check logs:
heroku logs --tailheroku config:set AI_PROVIDER=openai
heroku config:set OPENAI_API_KEY=your_openai_api_key
heroku config:set MODEL=gpt-4o-miniheroku config:set AI_PROVIDER=heroku
heroku config:set INFERENCE_KEY=your_api_key
heroku config:set INFERENCE_MODEL_ID=your_model
heroku config:set INFERENCE_URL=https://your-inference-endpoint.herokuapp.com- Check dyno status:
heroku ps- View logs:
heroku logs --tail --app your-app-name- Restart the app:
heroku restart- Check environment variables:
heroku confignpm run dev # Run in development mode with ts-node
npm run build # Compile TypeScript to JavaScript
npm start # Run the compiled JavaScript
npm run lint # Check code style and errors
npm run lint:fix # Auto-fix linting issues
npm run type-check # Run TypeScript type checking
npm test # Run Jest tests
npm run test:watch # Run Jest tests in watch mode
npm run test:coverage # Run Jest tests with coverage reportmybot/
βββ src/
β βββ index.ts # Main bot logic
βββ dist/ # Compiled JavaScript (generated)
βββ .github/
β βββ workflows/
β β βββ lint.yml # GitHub Actions CI/CD
β βββ dependabot.yml # Dependabot configuration
βββ eslint.config.js # ESLint configuration
βββ tsconfig.json # TypeScript configuration
βββ package.json # Node.js dependencies and scripts
βββ Procfile # Heroku process configuration
βββ .env # Environment variables (create this)
βββ .env.example # Environment variables template
βββ README.md # This fileTo add a new bot personality:
-
Get a Discord Bot Token:
- Go to https://discord.com/developers/applications
- Create a new application
- Create a bot and copy the token
-
Add to environment variables:
# Add to .env file
NEW_BOT_TOKEN=your_new_bot_token_here
# For Heroku
heroku config:set NEW_BOT_TOKEN=your_new_bot_token_here- Update the bot configuration in
src/index.ts:
const BOT_CONFIGS: BotConfig[] = [
// ...existing bots...
{
token: process.env.NEW_BOT_TOKEN || '',
name: 'NewBotName',
prompt: 'Your bot personality description here.',
model: BASE_MODEL,
channel: CHANNEL
}
];The project includes automated linting and type checking via GitHub Actions:
- Triggers: On push and pull requests to
mainbranch - Checks: ESLint, TypeScript compilation, and build verification
- Node.js: Version 22.x (configurable in
.github/workflows/lint.yml)
Dependabot is configured to automatically update dependencies:
- npm dependencies: Weekly updates on Mondays at 9:00 AM
- GitHub Actions: Weekly updates on Mondays at 9:00 AM
- Grouping: Related dependencies are grouped together (TypeScript ESLint, Discord.js, dev dependencies)
- Auto-labeling: PRs are automatically labeled for easy identification
- Security updates: Automatic security updates for vulnerable dependencies
Dependabot will create pull requests for:
- Production dependencies (
dependencies) - Development dependencies (
devDependencies) - GitHub Actions versions
- Security vulnerabilities (immediate updates)
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make changes and ensure tests pass:
npm run lint && npm run type-check - Commit changes:
git commit -m "Description of changes" - Push to branch:
git push origin feature-name - Create a Pull Request
For support or questions:
- Create an issue in the GitHub repository
- Check the Heroku logs:
heroku logs --tail - Verify environment variables:
heroku config