A Discord bot that allows users to interact with ChatGPT via slash commands, using the OpenRouter API. Built using the official discord.js
library with support for cooldowns and slash command handling.
Layer | Technology | Purpose |
---|---|---|
Language | Node.js | JavaScript runtime environment |
Bot API | discord.js | Interacts with the Discord API |
AI API | OpenRouter | Access to LLMs like ChatGPT via a unified API |
Server | Express | Lightweight web server to keep the bot alive |
Env Vars | dotenv | Manages sensitive configuration via .env |
Modules | Native ECMAScript Modules (import ) |
Modern JavaScript module system |
- 🔗 Connects to OpenRouter API to access ChatGPT (gpt-3.5-turbo or any supported model)
- ⚡ Slash command:
/ask
for real-time AI responses - 🕐 Cooldown system to prevent spam
- 🌐 Lightweight Express server to keep the bot alive (for platforms like Replit, Railway, etc.)
- Dotenv file setup
DISCORD_BOT_TOKEN=Your_Token
CLIENT_ID=Your_ID
OPENROUTER_API_KEY=Your_API_Key
GUILD_ID=Your_ID
PORT=3000
- Slash Command: /ask, /history
In Discord Server:-
/ask
question: How does AI work?
/history
Press Enter (To get 5 recent search history)
And receive an intelligent reply powered by OpenRouter's ChatGPT model.
- Clone the repo
git clone https://github.com/faizan-devs/Discord-Bot
cd chatgpt-discord-bot