Winter Gifts. A gift box is waiting in every Data API account until 31 December. Open your gift

Build a Discord card price bot: a /price command on a TCG price API

A complete slash command in discord.js: find the card, fetch its price, answer with an embed that names the market and the date, and stay inside the rate limit.

What does the bot do?

A member types /price card:charizard ex game:pokemon and the bot replies with the card's image, its current price, the market that price came from and when it was observed. That is two calls to the Flipzi Data API and about sixty lines of discord.js. The same pattern works for a Telegram or Slack bot; only the reply format changes.

You need Node 18 or newer, a Discord application with a bot token, and a Data API key. Create a free developer account to get one.

1. The two API calls

Search returns candidates; the price call takes the chosen id.

curl --fail-with-body --get 'https://data.flipzi.io/v1/cards/search' \
  --data-urlencode 'q=charizard ex' \
  --data-urlencode 'game=pokemon' \
  --data-urlencode 'page_size=5' \
  -H "X-API-Key: $FLIPZI_KEY"

curl --fail-with-body \
  'https://data.flipzi.io/v1/cards/0908653a-ce24-4d7e-811e-78c2935bd822/price?currency=eur' \
  -H "X-API-Key: $FLIPZI_KEY"

A search result carries id, name, set, number, rarity and image_url. A price row carries price_cents, price_formatted, market, confidence and updated_at. Run both in the playground to see full responses.

2. Register the slash command

Run this once. It registers /price with a card name, an optional game and an optional set code and number for members who want one exact card.

// register.js   (npm install discord.js)
import { REST, Routes, SlashCommandBuilder } from 'discord.js';

const command = new SlashCommandBuilder()
  .setName('price')
  .setDescription('Current price of a trading card')
  .addStringOption(o => o.setName('card').setDescription('Card name').setRequired(true))
  .addStringOption(o => o.setName('game').setDescription('Game').addChoices(
    { name: 'Pokémon', value: 'pokemon' },
    { name: 'Pokémon (Japanese)', value: 'pokemon-jp' },
    { name: 'One Piece', value: 'onepiece' },
    { name: 'Magic', value: 'mtg' },
    { name: 'Yu-Gi-Oh!', value: 'yugioh' },
    { name: 'Lorcana', value: 'lorcana' },
  ))
  .addStringOption(o => o.setName('number').setDescription('Collector number, e.g. 125'));

const rest = new REST().setToken(process.env.DISCORD_TOKEN);
await rest.put(Routes.applicationCommands(process.env.DISCORD_APP_ID), { body: [command.toJSON()] });
console.log('Registered /price');

The game ids are the ones GET /v1/catalog/games returns; add the others your community plays.

3. Answer it

// bot.js
import { Client, EmbedBuilder, Events, GatewayIntentBits } from 'discord.js';

const API = 'https://data.flipzi.io';
const HEADERS = { 'X-API-Key': process.env.FLIPZI_KEY };
const cache = new Map();                 // url -> { at, body }
const TTL_MS = 10 * 60 * 1000;

async function flipzi(path, params = {}) {
  const url = `${API}${path}?${new URLSearchParams(params)}`;
  const hit = cache.get(url);
  if (hit && Date.now() - hit.at < TTL_MS) return hit.body;
  const res = await fetch(url, { headers: HEADERS });
  if (res.status === 429) throw new Error('Busy, try again in a minute.');
  if (!res.ok) throw new Error(`Price service answered ${res.status}.`);
  const body = await res.json();
  cache.set(url, { at: Date.now(), body });
  return body;
}

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

client.on(Events.InteractionCreate, async (interaction) => {
  if (!interaction.isChatInputCommand() || interaction.commandName !== 'price') return;
  await interaction.deferReply();        // the API calls may take longer than 3 s
  try {
    const params = { q: interaction.options.getString('card'), page_size: 1 };
    const game = interaction.options.getString('game') ?? 'pokemon';
    const number = interaction.options.getString('number');
    params.game = game;
    if (number) params.number = number;

    const found = await flipzi('/v1/cards/search', params);
    const card = found.data[0];
    if (!card) return interaction.editReply('No card matched. Try the set number too.');

    const priced = await flipzi(`/v1/cards/${card.id}/price`, { currency: 'eur' });
    const price = priced.data.prices.find(p => p.grade === 'RAW');

    const embed = new EmbedBuilder()
      .setTitle(card.name)
      .setDescription(`${card.set.name} · #${card.number}${card.rarity ? ` · ${card.rarity}` : ''}`)
      .setThumbnail(card.image_url)
      .setFooter({ text: 'Pricing data by Flipzi' });

    if (price) {
      embed.addFields(
        { name: 'Price (ungraded)', value: price.price_formatted, inline: true },
        { name: 'Market', value: price.market, inline: true },
        { name: 'Observed', value: `<t:${Math.floor(Date.parse(price.updated_at) / 1000)}:R>`, inline: true },
      );
    } else {
      embed.addFields({ name: 'Price', value: 'No current price for this card.' });
    }
    await interaction.editReply({ embeds: [embed] });
  } catch (err) {
    await interaction.editReply(err.message);
  }
});

client.login(process.env.DISCORD_TOKEN);

Three details matter more than the rest:

  • Defer first. Discord drops an interaction that is not acknowledged within three seconds.
  • Say which card you priced. The first search result is not always the card the member meant, so the embed shows set and number. For exact matches, ask for the collector number.
  • An empty price list is not zero. Reply "no current price" rather than 0.00.

4. Graded and sold prices

The same handler extends with one parameter or one more call:

  • Graded: add grade=PSA_10 to the price call and read the row with that grade. Pro and above.
  • What it sold for: GET /v1/cards/{card_id}/sold returns a value from completed eBay sales with the number of sales behind it. Pro and above. See APIs with eBay sold data.
  • By condition on Cardmarket: GET /v1/cards/{card_id}/cardmarket returns the cheapest and median asking price per grade and language. Ultra and above. See Cardmarket prices by condition.
  • Movers of the week: GET /v1/market/movers for a scheduled post. Ultra and above, 5 units a call.

An endpoint outside the key's plan answers 403 PLAN_FEATURE_LOCKED and is not billed, so the bot can offer a command and explain the refusal.

Caching and rate limits

The cache above answers a repeated question for ten minutes without a call. That is what keeps a busy server inside the per-minute limit (60 requests a minute on Basic). Follow the Cache-Control header on each response if you want the cache to track the data rather than a fixed time. A 429 means slow down, not retry at once; the handler tells the member to try again.

Do not call the API on every keystroke of an autocomplete option. If you add autocomplete, debounce it or serve it from your own list of names built from /v1/catalog/sets/{set_id}/cards.

Which plan does a bot need?

  • Free: 500 units a month at 5 requests a minute. For building and testing; not for a bot that serves a community.
  • Basic: 15,000 units a month, about 7,500 price checks before caching, with commercial use.
  • Pro: adds graded and sold prices.
  • Ultra: adds Cardmarket prices by condition and market movers.

Attribution ("Pricing data by Flipzi") is requested, not required. Current prices and allowances are on API pricing; storage and display rules are in caching, storage and licensing.

Get the bot answering today

A free key is enough to build and test the whole command. Move to a paid plan when it goes live in a server.

Get a free API key Try it in the playground Compare API plans

Straight answers

Which API can a Discord bot use for trading card prices?
The Flipzi Data API is a REST API with an API key, so any bot framework can call it. A price command needs two endpoints: GET /v1/cards/search to find the card and GET /v1/cards/{card_id}/price for its current price, one unit each.
Where does the API key go in a bot?
In an environment variable on the machine that runs the bot, sent in the X-API-Key header from your code. Never put it in a client, a public repository or a Discord message.
Can the bot show graded prices such as PSA 10?
Yes, with grade=PSA_10 on the price request, on Pro and above. A supported grade does not mean every card has a figure for it; answer "no price" when the list is empty.
Can I run the bot on the free plan?
You can build and test it on the free plan (500 units a month at 5 requests a minute). The free plan is for development and evaluation only; a bot running for a community is production use and needs a paid plan.
How many price checks does a plan cover?
A check is a search and a price call, two units. Basic has 15,000 units a month, about 7,500 checks before caching. Cache answers for a few minutes and repeat questions cost nothing.