Duckbot is a powerful AI chatbot built with Discord.js, OpenAI, and Replicate. It can:
- Respond to text-based questions using OpenAI.
- Generate AI-generated images directly in the chat using Replicate.
- Ask AI Questions: Use the
!askcommand to get answers powered by OpenAI. - Generate Images: Use the
!imagecommand to get AI-generated images right in Discord.
| Command | Description | Example |
|---|---|---|
!ask |
Get a text-based response from OpenAI. | !ask What is AI? |
!image |
Get an AI-generated image from Replicate. | !image futuristic city |
git clone https://github.com/YOUR_USERNAME/discord-ai-bot.git
cd discord-ai-botCreate a .env file in the root of your project and add the following:
DISCORD_TOKEN=YOUR_DISCORD_BOT_TOKEN
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
REPLICATE_API_TOKEN=YOUR_REPLICATE_API_KEYReplace the placeholders with your actual API keys:
- DISCORD_TOKEN: Copy from Discord Developer Portal.
- OPENAI_API_KEY: Copy from OpenAI's API key page.
- REPLICATE_API_TOKEN: Copy from Replicate API.
Run the following command to install the required dependencies:
npm installDependencies include:
discord.jsfor interacting with Discord.dotenvfor managing environment variables.replicatefor AI-generated images.openaifor AI text responses.
Run the bot locally:
node index.jsYou should see a message in the terminal saying:
Bot is online as [BotName]
- Go to https://railway.app and create an account.
- Once logged in, click "New Project".
- Click GitHub Repo and select your
discord-ai-botrepository. - Railway will automatically detect your project.
- Click on your project.
- Go to Settings > Variables.
- Add the following environment variables:
DISCORD_TOKEN=YOUR_DISCORD_BOT_TOKEN
OPENAI_API_KEY=YOUR_OPENAI_API_KEY
REPLICATE_API_TOKEN=YOUR_REPLICATE_API_KEY
- Click Deploy and wait for the process to complete.
- When the logs show
Bot is online, your bot is now running!
- Add the bot to your Discord server using the OAuth2 URL from the Discord Developer Portal.
- Use the following commands in your server:
!ask What is AI?– The bot responds with an OpenAI-generated answer.!image sunset landscape– The bot responds with an AI-generated image.
Your Discord AI bot is now live and ready to use! Let me know if you need further assistance or additional features!