DEV Community

Himanshu Jain
Himanshu Jain

Posted on

How to Build a Discord Bot that Tracks Free Games (Epic & Steam)

We all love free games. But we all hate remembering to claim them.

Every Thursday, Epic Games drops a free title. Steam randomly makes paid games free for a weekend. If you aren't glued to Reddit, you usually miss it.

Today, we fix that.

We’ll build LootBot, a simple Discord bot that checks for active freebies and posts them to your server.


❌ The Old Way

Scrape the Epic Store website using Puppeteer:

  • Slow
  • Heavy
  • Gets IP banned

βœ… The New Way

Use Game Deals & Freebies API:

  • Free
  • Fast
  • No scraping headaches

Let’s get coding. 😺


🧩 Step 1: The Setup

1. Create a Discord Bot Token

  1. Go to the Discord Developer Portal
  2. Click New Application β†’ name it LootBot
  3. Open the Bot tab β†’ click Add Bot
  4. Scroll to Privileged Gateway Intents
  5. Enable Message Content Intent
  6. Copy your Bot Token and save it

2. Initialize the Node.js Project

npm init -y
npm install discord.js axios dotenv
Enter fullscreen mode Exit fullscreen mode

πŸ”‘ Step 2: Get Your Free API Key

We aren’t scraping websites today. It’s 2026 β€” we use APIs.

We’ll use Game Deals & Freebies API from RapidAPI. It aggregates data from Epic Games, Steam, and GamerPower into a clean JSON feed.

  1. Go to Game Deals & Freebies API on RapidAPI
  2. Click Subscribe to Test (Basic tier is free)
  3. Copy your X-RapidAPI-Key

🧠 Step 3: The Code

1. Environment Variables

Create a file named .env:

DISCORD_TOKEN=yourdiscordbottoken_here
RAPIDAPI_KEY=yourrapidapikeyhere
Enter fullscreen mode Exit fullscreen mode

2. Bot Logic (index.js)

The bot listens for !loot and replies with currently active free games.

require('dotenv').config();
const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
const axios = require('axios');

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent
    ]
});

async function getFreeGames() {
    const options = {
        method: 'GET',
        url: 'https://game-deals-freebies-api.p.rapidapi.com/epic',
        headers: {
            'X-RapidAPI-Key': process.env.RAPIDAPI_KEY,
            'X-RapidAPI-Host': 'game-deals-freebies-api.p.rapidapi.com'
        }
    };

    try {
        const response = await axios.request(options);
        return response.data.active;
    } catch (error) {
        console.error('API Error:', error);
        return [];
    }
}

client.on('messageCreate', async (message) => {
    if (message.author.bot) return;

    if (message.content === '!loot') {
        await message.channel.send('πŸ” Scanning for freebies...');

        const games = await getFreeGames();

        if (games.length === 0) {
            return message.reply('No free games found right now. Check back later!');
        }

        games.forEach(game => {
            const embed = new EmbedBuilder()
                .setColor(0x0099FF)
                .setTitle(game.title)
                .setDescription(game.description)
                .setImage(game.image)
                .addFields(
                    { name: 'Original Price', value: game.originalPrice || 'Free', inline: true },
                    { name: 'Status', value: 'πŸ”₯ Active Now', inline: true }
                )
                .setURL(game.storeUrl)
                .setFooter({ text: 'Powered by Game Deals & Freebies API' });

            message.channel.send({ embeds: [embed] });
        });
    }
});

client.on('ready', () => {
    console.log(`😺 LootBot is online as ${client.user.tag}!`);
});

client.login(process.env.DISCORD_TOKEN);
Enter fullscreen mode Exit fullscreen mode

▢️ Step 4: Run It

node index.js
Enter fullscreen mode Exit fullscreen mode

Invite the bot to your server (via OAuth2 in the Discord Developer Portal), type:

!loot
Enter fullscreen mode Exit fullscreen mode

And watch the magic happen ✨


πŸ€” Why Use an API Instead of Scraping?

Scraping works β€” until it doesn’t.

  • Speed – APIs respond in milliseconds
  • Maintenance – HTML changes break scrapers
  • Bandwidth – Clean JSON instead of heavy HTML
  • Reliability – No IP bans or CAPTCHAs

πŸš€ What’s Next?

You can expand LootBot to:

  • ⏰ Auto-check freebies every Thursday using node-cron
  • πŸ’° Track discounts via the /deals endpoint
  • πŸ”‘ Find Steam beta keys using /freebies
  • πŸ“’ Auto-ping roles when new games drop

πŸ”— Resources

Happy coding! 😺

Top comments (0)