An easy and customizable template to build Discord bots powered by LLM (Large Language Models). With this project, you can run personalized slash commands and easily extend the bot’s behavior for your server.
- Connects to LLM APIs (e.g., OpenAI).
- Ready-to-use slash command structure.
- Personality and behavior fully customizable.
- Written in JavaScript (Node.js).
- Simple, extendable, and beginner-friendly.
gen-ai-discord-bot/
├── .gitignore
├── README.md
├── deploy-commands.js
├── index.js
├── package.json
├── package-lock.json
└── viserion.jpg
- Node.js version 18+
- An account in the Discord Developer Portal
- An API key for the LLM provider you want to integrate (e.g., OpenAI)
To run the bot, you’ll need three important values from the Discord Developer Portal:
-
Create an Application
- Go to Discord Developer Portal.
- Click New Application, give it a name (e.g., Viserion Bot), and save.
-
Create the Bot User
-
Inside your new application, go to the Bot tab.
-
Click Add Bot → confirm.
-
Here you’ll find the Bot Token → copy it and use it as
DISCORD_TOKENin your.env.⚠️ Keep this token secret! If leaked, anyone can control your bot.
-
-
Get the Client ID
- Go to the OAuth2 → General tab.
- Copy the Application ID → this is your
CLIENT_ID.
-
Get the Guild (Server) ID
- In Discord, go to User Settings → Advanced and enable Developer Mode.
- Right-click your server name → Copy Server ID → this is your
GUILD_ID.
-
Invite the Bot to Your Server
- Go to OAuth2 → URL Generator.
- Under Scopes, check
botandapplications.commands. - Under Bot Permissions, select the permissions your bot needs (at least Send Messages and Use Slash Commands).
- Copy the generated URL, paste it into your browser, and invite the bot to your server.
- Clone this repository:
git clone https://github.com/BabiDoo/gen-ia-discord-bot.git
cd gen-ia-discord-bot- Install the dependencies:
npm install- Create a
.envfile at the project root and add your credentials:
DISCORD_TOKEN=your_discord_bot_token
CLIENT_ID=your_discord_client_id
GUILD_ID=your_discord_guild_id
OPENAI_API_KEY=your_openai_api_key- Deploy slash commands to your Discord server:
node deploy-commands.js- Start the bot:
node index.jsIn your Discord server, type:
/fact
And the bot will reply with a random Game of Thrones fact (or whatever you configure).
Contributions are welcome! To contribute:
- Fork this repository
- Create a new branch:
git checkout -b feature-name - Commit your changes:
git commit -m 'Added a new feature' - Push to your branch:
git push origin feature-name - Open a Pull Request