Build a Horoscope Bot for Telegram or Discord in Under an Hour
Step-by-step guide to building a daily horoscope bot for Telegram or Discord using an astrology API. Code examples, architecture, and deployment tips.
Build a Horoscope Bot for Telegram or Discord in Under an Hour
Chat bots are one of the fastest ways to put astrology content in front of users. Telegram has over 900 million monthly active users. Discord has 200 million. Both platforms support bot development with mature APIs, and both audiences actively engage with horoscope and astrology content.
A horoscope bot is a perfect first project if you are exploring astrology API integration. The scope is tight (daily horoscopes by zodiac sign), the user interaction is simple (pick a sign, get a reading), and the viral potential is real (users share readings in group chats).
This guide walks through the architecture, the code, and the deployment for both platforms.
Architecture Overview
The bot architecture is straightforward:
User sends command (/horoscope aries)
|
Bot receives message
|
Parse zodiac sign from input
|
Call astrology API with sign + current date
|
Format response
|
Send reply to user
What You Need
- A Telegram Bot Token (from @BotFather) or Discord Bot Token (from Discord Developer Portal)
- An astrology API key (from RoxyAPI)
- Node.js/Bun runtime
- Basic JavaScript/TypeScript knowledge
Why an API Instead of Hardcoded Content
You could hardcode 12 daily horoscopes and rotate them. But:
- Content gets stale. Users notice when readings repeat.
- No personalization. API-powered horoscopes can incorporate actual planetary positions, transits, and astronomical data.
- Limited features. Hardcoded content cannot expand to birth charts, compatibility, tarot readings, or other features your users will request.
- Maintenance burden. You become a content writer instead of a developer.
An API handles the content. You handle the bot experience.
Telegram Bot: Step by Step
Step 1: Create Your Bot with BotFather
Open Telegram, search for @BotFather, and send /newbot. Follow the prompts to name your bot and get your bot token.
Step 2: Set Up the Project
mkdir horoscope-bot && cd horoscope-bot
npm init -y
npm install node-telegram-bot-api
Step 3: Build the Bot
const TelegramBot = require('node-telegram-bot-api');
const BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN;
const API_KEY = process.env.ROXYAPI_KEY;
const API_BASE = 'https://api.roxyapi.com/api/v2';
const bot = new TelegramBot(BOT_TOKEN, { polling: true });
const ZODIAC_SIGNS = [
'aries', 'taurus', 'gemini', 'cancer',
'leo', 'virgo', 'libra', 'scorpio',
'sagittarius', 'capricorn', 'aquarius', 'pisces'
];
// /start command
bot.onText(/\/start/, (msg) => {
const welcome = `Welcome to the Horoscope Bot!
Commands:
/horoscope [sign] - Get your daily horoscope
/signs - List all zodiac signs
/compatibility [sign1] [sign2] - Check compatibility
Example: /horoscope aries`;
bot.sendMessage(msg.chat.id, welcome);
});
// /signs command
bot.onText(/\/signs/, (msg) => {
const signList = ZODIAC_SIGNS
.map(s => s.charAt(0).toUpperCase() + s.slice(1))
.join('\n');
bot.sendMessage(msg.chat.id, `Zodiac Signs:\n\n${signList}`);
});
// /horoscope command
bot.onText(/\/horoscope (.+)/, async (msg, match) => {
const sign = match[1].toLowerCase().trim();
if (!ZODIAC_SIGNS.includes(sign)) {
bot.sendMessage(msg.chat.id,
`Unknown sign "${sign}". Use /signs to see all options.`
);
return;
}
try {
const response = await fetch(
`${API_BASE}/western-astrology/horoscope/daily?sign=${sign}`,
{
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
}
}
);
const data = await response.json();
const message = `${sign.charAt(0).toUpperCase() + sign.slice(1)} - Daily Horoscope
${data.horoscope}
Lucky Number: ${data.lucky_number || 'N/A'}
Mood: ${data.mood || 'N/A'}`;
bot.sendMessage(msg.chat.id, message);
} catch (error) {
bot.sendMessage(msg.chat.id,
'Could not fetch your horoscope. Please try again.'
);
}
});
Step 4: Run It
TELEGRAM_BOT_TOKEN=your_token ROXYAPI_KEY=your_key node index.js
Your bot is live. Send /horoscope aries in Telegram to test.
Discord Bot: Step by Step
Step 1: Create a Discord Application
Go to the Discord Developer Portal, create a new application, add a bot, and copy the bot token. Invite the bot to your server using the OAuth2 URL generator with bot and applications.commands scopes.
Step 2: Set Up the Project
mkdir horoscope-discord-bot && cd horoscope-discord-bot
npm init -y
npm install discord.js
Step 3: Build the Bot
const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
const API_KEY = process.env.ROXYAPI_KEY;
const API_BASE = 'https://api.roxyapi.com/api/v2';
const SIGN_EMOJIS = {
aries: '♈', taurus: '♉', gemini: '♊', cancer: '♋',
leo: '♌', virgo: '♍', libra: '♎', scorpio: '♏',
sagittarius: '♐', capricorn: '♑', aquarius: '♒', pisces: '♓'
};
client.on('messageCreate', async (message) => {
if (message.author.bot) return;
if (message.content.startsWith('!horoscope')) {
const args = message.content.split(' ');
const sign = args[1]?.toLowerCase();
if (!sign || !SIGN_EMOJIS[sign]) {
message.reply(
'Usage: `!horoscope [sign]`\nExample: `!horoscope aries`'
);
return;
}
try {
const response = await fetch(
`${API_BASE}/western-astrology/horoscope/daily?sign=${sign}`,
{
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
}
}
);
const data = await response.json();
const embed = new EmbedBuilder()
.setTitle(`${SIGN_EMOJIS[sign]} ${sign.charAt(0).toUpperCase() + sign.slice(1)} Daily Horoscope`)
.setDescription(data.horoscope)
.setColor(0x7C3AED)
.addFields(
{ name: 'Lucky Number', value: String(data.lucky_number || 'N/A'), inline: true },
{ name: 'Mood', value: data.mood || 'N/A', inline: true }
)
.setFooter({ text: 'Powered by RoxyAPI' })
.setTimestamp();
message.reply({ embeds: [embed] });
} catch (error) {
message.reply('Could not fetch horoscope. Please try again.');
}
}
});
client.login(process.env.DISCORD_BOT_TOKEN);
Step 4: Run It
DISCORD_BOT_TOKEN=your_token ROXYAPI_KEY=your_key node index.js
Type !horoscope aries in any channel the bot has access to.
Expanding Beyond Daily Horoscopes
Once the basic bot works, you can add features incrementally:
Birth Chart Command
/birthchart 1990-03-15 14:30 New York
Call the birth chart API endpoint with the user's birth details. Return Sun, Moon, and Rising signs with descriptions. This creates a premium feel with minimal additional code.
Compatibility Command
/compatibility aries scorpio
Compare two zodiac signs using the compatibility endpoint. Return overall compatibility score and relationship dynamics. This feature drives the most engagement in group chats.
Tarot Draw
/tarot
/tarot three-card
Draw a single card or three-card spread. Tarot adds variety for users who engage daily and want more than horoscopes. The RoxyAPI Tarot API returns card data with meanings, keywords, and imagery descriptions.
Daily Scheduled Messages
Set up a cron job or scheduled function that posts the daily horoscope for each sign in a dedicated channel every morning. This creates a daily touchpoint that keeps the bot server active.
const cron = require('node-cron');
// Post daily horoscopes at 8 AM
cron.schedule('0 8 * * *', async () => {
const channel = client.channels.cache.get(HOROSCOPE_CHANNEL_ID);
for (const sign of Object.keys(SIGN_EMOJIS)) {
const data = await fetchHoroscope(sign);
await channel.send(`${SIGN_EMOJIS[sign]} **${sign.toUpperCase()}**: ${data.horoscope}`);
}
});
Caching Strategy
API calls cost credits. Smart caching keeps costs minimal:
Daily horoscopes: Cache for 24 hours. All users requesting the same sign on the same day get the cached response. 12 signs = 12 API calls per day maximum.
Birth charts: Cache permanently per user. A birth chart never changes. Calculate once, store the result, and serve from cache forever.
Tarot draws: Do not cache. Each draw should be unique. This is where most of your API usage will go if tarot is popular.
Compatibility: Cache per sign pair. There are 78 unique sign pairs (12 choose 2 + 12 same-sign pairs). Cache all of them and refresh weekly.
With caching, a bot serving thousands of daily users can operate on RoxyAPI's Starter plan (5,000 requests/month).
Deployment Options
Railway or Render (Simplest)
Push your code to GitHub, connect to Railway or Render, set environment variables, and deploy. Both platforms support always-on processes for bot hosting.
Cost: Free tier available on both platforms for low-traffic bots.
VPS (Most Control)
A $5/month VPS (DigitalOcean, Hetzner) runs the bot 24/7 with full control. Use PM2 or systemd to keep the process running.
Serverless (Not Ideal for Polling)
Telegram and Discord bots using polling mode need a persistent process. Serverless functions (AWS Lambda, Vercel) work for webhook-based bots but add complexity.
Recommendation for starting: Railway or Render. Zero ops overhead, free or near-free for small bots, and easy redeployment.
Monetization Ideas
Once your bot has users, consider:
Freemium model: Daily horoscope free. Birth chart, compatibility, and tarot require a premium tier (Telegram Bot Payments API supports in-app purchases).
Server premium: For Discord, offer a premium version for server owners. Exclusive features (detailed weekly forecasts, personalized readings) available only in servers that subscribe.
Tip jar: Accept donations through cryptocurrency or payment links. Astrology users are often generous supporters.
White-label: Build the bot once, deploy customized versions for astrology influencers or content creators who want their own branded bot.
Frequently Asked Questions
Q: How much does it cost to run a horoscope bot? A: Minimal. The bot hosting is free or under $5/month. With smart caching, the API usage for daily horoscopes (12 calls/day) plus birth charts and compatibility stays well within RoxyAPI's Starter plan at $39/month for 5,000 requests. A bot serving 1,000+ daily users can operate profitably on this plan.
Q: Can I add astrology features to an existing bot? A: Absolutely. The horoscope functionality is self-contained. Add the astrology commands alongside your existing bot features. The API calls are independent and do not require changes to your bot's existing architecture.
Q: Do I need to know astrology to build this bot? A: No. The API handles all astrological calculations and generates the horoscope content. You need to know how to make HTTP requests and format bot responses. Zero astrology knowledge required. The API documentation at RoxyAPI docs explains every endpoint and response field.
Q: Which platform should I build for first? A: Telegram is simpler to start with (easier bot creation process, simpler API). Discord has richer formatting options (embeds with colors, fields, and images). Choose the platform where your target audience already exists. If you are unsure, start with Telegram and port to Discord later.
Q: Can the bot handle multiple languages? A: Yes. You handle the translation layer in your bot code. The API returns English content, and you can either translate it using a translation API or maintain response templates in multiple languages. For the Indian market, Hindi, Tamil, and Telugu translations dramatically expand reach.
Q: How do I prevent API abuse from bot users? A: Implement per-user rate limiting in your bot code. Allow each user a maximum number of requests per day (e.g., 5 horoscope checks, 1 birth chart, 3 tarot draws). This protects your API quota and prevents a single user from consuming your monthly allocation.
Start building your horoscope bot today. Get an API key at RoxyAPI pricing, check the API documentation for all available endpoints, or explore the full product suite to plan your bot's feature set.