Discord movie bot tutorial with discord.js
A Discord movie bot is one slash command, a bot token and an API key. This tutorial builds it with discord.js v14: /movie replies with an embed of poster, ratings, runtime and genres, using 2 API requests per new title. The bot shows movie information and ratings and never streams or downloads movies.
A Discord movie bot needs one slash command, a bot token and an API key: type /movie fight club and the bot replies with an embed that holds the poster, IMDb and Kinopoisk scores, runtime and genres. The bot searches titles and shows information and ratings; it does not stream or download movies. A new title costs 2 API requests and a cached title costs 0, so the 20 requests per minute plan serves about 10 new lookups a minute.
What do you need to build a Discord movie bot?
You build a Discord bot with one slash command, /movie title. It replies with an embed that shows the poster, year, IMDb and Kinopoisk scores, runtime, genres and a short overview.
| You need | Value |
|---|---|
| Runtime | Node.js 20.6 or newer, for the --env-file option and the built-in fetch |
| Packages | 1: discord.js v14 |
| Discord | An application with a bot token, the bot and applications.commands scopes and a test server id |
| Key | An amodb key, 32 lowercase hex characters. The TMDB API key page shows how to get one |
| Intents | Guilds only |
| Time | About 25 minutes |
Which calls does the Discord movie bot make, and what do they cost?
Every call to the API costs 1 request, and a reply served from the edge cache counts too. The poster comes from a separate host that needs no key and is not counted.
| Call | Path | Cost | Bot cache |
|---|---|---|---|
| Search | GET / | 1 request | 10 minutes |
| Details with ratings | GET / | 1 request | 6 hours |
| Poster thumbnail | https:/ | 0 requests | Discord fetches it |
The limit belongs to your amodb account, so every server that uses your bot shares it, along with any other app on the same account. A second key does not add requests. At 20 requests per minute that is 10 new titles a minute, and an account cannot pass 28,800 requests a day on that plan. The TMDB search API page describes the search call, and the movie details API page explains append_to_response.
Step 1: Get your credentials
Buy an amodb plan with your email and sign in with the 6 digit code amodb then emails you to get your first key, then create a Discord application with a bot token and add the bot to a test server.
Open amodb pricing to pick the plan. Every plan has every TMDB v3 compatible endpoint, images, 14 languages and the extensions. The plans differ in rate (Lite 20, Pro 40, Pro+ 120 requests per minute, from $5.19 a month), and only Pro+ also has the all in one endpoint GET /. There is no free tier or trial.
In the Discord developer portal create an application, add a bot to it and copy the bot token. Open the OAuth2 page, use the URL generator, tick the bot and applications.commands scopes and open the link to add the bot to a test server. Copy the server id as well. Put the values in a .env file and keep it out of Git:
DISCORD_TOKEN=YOUR_BOT_TOKEN
DISCORD_GUILD_ID=YOUR_TEST_SERVER_ID
AMODB_KEY=YOUR_API_KEYStep 2: Create the project
Create a Node.js project named movie-discord-bot and install discord.js.
The type setting turns on import syntax. See authentication for the header and query forms of the key.
mkdir movie-discord-bot && cd movie-discord-bot
npm init -y
npm pkg set type=module
npm install discord.jsStep 3: Register the slash command
Describe a /movie command with a required title option using SlashCommandBuilder, and let the bot send it to Discord once it is ready.
With DISCORD_GUILD_ID set, the command appears in that server at once. Leave the variable unset to register it everywhere.
import { Client, Events, GatewayIntentBits, SlashCommandBuilder } from 'discord.js';
const movieCommand = new SlashCommandBuilder()
.setName('movie')
.setDescription('Look up a movie')
.addStringOption((option) =>
option.setName('title').setDescription('Movie title').setRequired(true).setMaxLength(100),
);
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, async (ready) => {
await ready.application.commands.set([movieCommand.toJSON()], process.env.DISCORD_GUILD_ID);
console.log(`Logged in as ${ready.user.tag}`);
});Step 4: Build the embed
Build an embed from the details call, which adds append_ so the scores arrive with the movie.
Each source is an object with value and votes, or null when the score is not known. The embed prints value and says "not known" for null. The poster is https:/ plus poster_path; see the TMDB image URL page for other sizes. An embed description can hold 4096 characters, and the code keeps 400. Add EmbedBuilder to the import line and define the POSTER constant, as the final listing does.
function movieEmbed(movie) {
const score = (source) => (source ? String(source.value) : 'not known');
const genres = (movie.genres ?? []).map((genre) => genre.name).join(', ') || 'not known';
const embed = new EmbedBuilder()
.setTitle(`${movie.title} (${(movie.release_date || '').slice(0, 4) || 'n/a'})`)
.setDescription((movie.overview || 'No overview yet.').slice(0, 400))
.addFields(
{ name: 'IMDb', value: score(movie.ratings?.imdb), inline: true },
{ name: 'Kinopoisk', value: score(movie.ratings?.kinopoisk), inline: true },
{ name: 'Runtime', value: movie.runtime ? `${movie.runtime} min` : 'not known', inline: true },
{ name: 'Genres', value: genres },
);
if (movie.poster_path) embed.setThumbnail(POSTER + movie.poster_path);
return embed;
}Step 5: Handle errors and rate limits
Call deferReply() first, because Discord wants an answer within 3 seconds.
A search plus a details call, or a wait after a 429, can take longer. After a deferral you have 15 minutes to call editReply().
| Case | Cause | Bot reaction |
|---|---|---|
| 401 | Key missing or invalid (status_code 7 for an invalid key) | Log it, tell the channel, exit. Every command would fail. |
| 429 | Over your requests per minute (status_code 25) | Wait Retry-After seconds, capped at 10, retry twice, then ask the user to try later. |
Empty results | No title matches | Reply that no movie was found. |
| Timeout after 8 seconds | Slow network | Reply that the service did not answer. |
The retry loop in the final listing reads Retry-After from the response headers. The error body uses the TMDB shape {"success": false,. See error codes and the TMDB API rate limit page for every code.
function describeError(error) {
if (error instanceof AmodbError && error.status === 429) {
return 'Too many lookups right now. Try again in a minute.';
}
return 'The movie service did not answer. Try again later.';
}Step 6: Cache answers
Cache search results for 10 minutes and movie details for 6 hours in a small TtlCache class, the same lifetimes as the edge.
The rate limit check runs before the edge cache, so only a cache in your bot saves requests per minute. The class is in the final listing. Two people asking for the same title within 10 minutes then cost two requests in total, not four.
Step 7: The complete bot
Save the complete listing below as bot.js and start it with the .env file.
import {
Client,
EmbedBuilder,
Events,
GatewayIntentBits,
SlashCommandBuilder,
} from 'discord.js';
const { DISCORD_TOKEN, DISCORD_GUILD_ID, AMODB_KEY } = process.env;
if (!DISCORD_TOKEN || !AMODB_KEY) {
console.error('Set DISCORD_TOKEN and AMODB_KEY first.');
process.exit(1);
}
const API = 'https://api.amodb.dev/3';
const POSTER = 'https://img.amodb.dev/t/p/w342';
class AmodbError extends Error {
constructor(status) {
super(`amodb returned ${status}`);
this.status = status;
}
}
class TtlCache {
#items = new Map();
get(key) {
const item = this.#items.get(key);
if (!item) return undefined;
if (item.expires < Date.now()) {
this.#items.delete(key);
return undefined;
}
return item.value;
}
set(key, value, ttlMs) {
this.#items.set(key, { value, expires: Date.now() + ttlMs });
}
}
const cache = new TtlCache();
async function amodb(path, params, ttlMs) {
const url = new URL(API + path);
url.search = new URLSearchParams(params).toString();
const cached = cache.get(url.href);
if (cached) return cached;
for (let attempt = 0; attempt < 3; attempt++) {
const res = await fetch(url, {
headers: { Authorization: `Bearer ${AMODB_KEY}` },
signal: AbortSignal.timeout(8_000),
});
if (res.status === 429 && attempt < 2) {
const wait = Math.min(Number(res.headers.get('retry-after')) || 3, 10);
await new Promise((resolve) => setTimeout(resolve, wait * 1000));
continue;
}
if (!res.ok) throw new AmodbError(res.status);
const body = await res.json();
cache.set(url.href, body, ttlMs);
return body;
}
}
function movieEmbed(movie) {
const score = (source) => (source ? String(source.value) : 'not known');
const genres = (movie.genres ?? []).map((genre) => genre.name).join(', ') || 'not known';
const embed = new EmbedBuilder()
.setTitle(`${movie.title} (${(movie.release_date || '').slice(0, 4) || 'n/a'})`)
.setDescription((movie.overview || 'No overview yet.').slice(0, 400))
.addFields(
{ name: 'IMDb', value: score(movie.ratings?.imdb), inline: true },
{ name: 'Kinopoisk', value: score(movie.ratings?.kinopoisk), inline: true },
{ name: 'Runtime', value: movie.runtime ? `${movie.runtime} min` : 'not known', inline: true },
{ name: 'Genres', value: genres },
);
if (movie.poster_path) embed.setThumbnail(POSTER + movie.poster_path);
return embed;
}
function describeError(error) {
if (error instanceof AmodbError && error.status === 429) {
return 'Too many lookups right now. Try again in a minute.';
}
return 'The movie service did not answer. Try again later.';
}
const movieCommand = new SlashCommandBuilder()
.setName('movie')
.setDescription('Look up a movie')
.addStringOption((option) =>
option.setName('title').setDescription('Movie title').setRequired(true).setMaxLength(100),
);
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
client.once(Events.ClientReady, async (ready) => {
await ready.application.commands.set([movieCommand.toJSON()], DISCORD_GUILD_ID);
console.log(`Logged in as ${ready.user.tag}`);
});
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand() || interaction.commandName !== 'movie') return;
await interaction.deferReply();
try {
const title = interaction.options.getString('title', true).trim();
const found = await amodb('/search/movie', { query: title, language: 'en-US' }, 10 * 60_000);
const hit = found.results[0];
if (!hit) {
await interaction.editReply(`No movie found for "${title}".`);
return;
}
const movie = await amodb(
`/movie/${hit.id}`,
{ language: 'en-US', append_to_response: 'ratings' },
6 * 60 * 60_000,
);
await interaction.editReply({ embeds: [movieEmbed(movie)] });
} catch (error) {
console.error('Lookup failed:', error);
if (error instanceof AmodbError && error.status === 401) {
console.error('amodb rejected AMODB_KEY (401). Fix the key and restart.');
await interaction.editReply('The bot key was rejected. The owner has to fix it.').catch(() => {});
await client.destroy();
process.exit(1);
}
await interaction.editReply(describeError(error)).catch(() => {});
}
});
process.on('unhandledRejection', (error) => console.error('Unhandled rejection:', error));
await client.login(DISCORD_TOKEN);Start the bot with the .env file, then type /movie in the test server and enter a title.
For /movie fight club the first search hit is movie 550, and the embed holds the title Fight Club (1999), the overview cut to 400 characters and the thumbnail https:/, plus these fields:
| Field | Value |
|---|---|
| IMDb | 8.8 |
| Kinopoisk | 8.7 |
| Runtime | 139 min |
| Genres | Drama, Thriller |
The first lookup of a title makes two calls, and later lookups inside the cache lifetime make none. A 401 stops the process after a message, and a timeout produces the generic reply.
node --env-file=.env bot.jsHow do I add more scores to a Discord movie rating bot?
Add one field per source to the addFields call in movieEmbed, and reuse the score helper so a null source prints "not known".
IMDb, Kinopoisk and TMDB are out of 10. Metacritic and Rotten Tomatoes are out of 100, and either can be null for a title, so amodb never promises a value for them. The details call already returns all five sources, so the extra fields cost no extra request.
A Discord embed holds up to 25 fields, so five scores fit with room to spare. The movie ratings API page lists each source and its null rules.
{ name: 'Metacritic (of 100)', value: score(movie.ratings?.metacritic), inline: true },
{ name: 'Rotten Tomatoes (of 100)', value: score(movie.ratings?.rotten_tomatoes), inline: true },
{ name: 'TMDB (of 10)', value: score(movie.ratings?.tmdb), inline: true },How do I build a Discord movie recommendation bot?
Ask for recommendations in the same details call, and add one field with the first five titles.
Change append_ in the details call to 'ratings,. The list arrives under its own key in the TMDB shape, a results array of up to 20 movies. Put these lines before return embed in movieEmbed:
The call is still 1 request, because append_to_response merges the list into the details reply. Separate commands are also possible: GET / returns 20 movies, and GET / returns 20 similar ones, each for 1 request. The movie mood API adds a 0 to 10 mood meter for each title, which is another way to filter suggestions.
const similar = (movie.recommendations?.results ?? [])
.slice(0, 5)
.map((item) => item.title)
.join('\n');
embed.addFields({ name: 'Similar movies', value: similar || 'none' });Is the TMDB API free to use for a Discord bot?
The TMDB API is free only while your bot earns nothing, and a bot that takes donations or sells a premium tier needs a paid plan.
TMDB staff said on the TMDB forum (2026-10-15) that an app counts as commercial the moment it earns revenue from ads, in-app purchases, donations or subscriptions. They quoted the commercial plan at $149 a month for companies under $1M revenue, with a custom quote above (2026-03-31), and there is no small tier between free and $149. TMDB's terms of use also require its logo with a not-endorsed notice and limit caching to 6 months.
| Project | TMDB | amodb |
|---|---|---|
| Hobby bot, earns nothing | Free under TMDB's terms | Paid, from $5.19 a month, no free tier |
| Bot with donations, ads or a premium tier | $149 a month under $1M revenue, custom quote above | From $5.19 a month. No extra charge; the terms do not prohibit it |
| Logo or attribution | TMDB logo and notice required | No amodb logo; credit JustWatch and licensed texts and images as marked |
amodb plans cost $5.19, $6.19 or $7.19 a month, which is 3.5% to 4.8% of $149, and longer periods save up to 40 percent. Pay by card, Apple Pay or Google Pay, prepaid for 1, 3, 6, 12 or 24 months; those payments do not renew automatically. Patreon is monthly and renews on Patreon until the member cancels there. Do not resell raw API access or share keys. Read Is the TMDB API free? for the full comparison.
Next steps
- Add autocomplete for the
titleoption with the TMDB search API, which has a 10 minute edge cache. - Add a
/trendingcommand using the TMDB trending API. - Add a trailer button with the TMDB trailer API endpoint.
- Build the same command for Telegram, or read the quickstart for a first request in any language.
- Browse every guide in the tutorials hub.