How to Show a Random Movie Selection in a Discord Bot Embed

Assistance Needed for Discord Bot Embed

Hello everyone! I’m developing a Discord bot that randomly selects a movie from a list and posts it in a channel. The random selection works perfectly, but I want to enhance the display by using an embed to present the chosen movie instead of plain text.

Here’s the code I have so far:

var movies = ["Avatar", "Inception", "Titanic", "Interstellar"];
var selectedIndex = Math.floor(Math.random() * movies.length);

if (message.content.startsWith(prefix + "movie")) {
    message.channel.send(movies[selectedIndex]);
}

Currently, the bot sends the movie title as regular text, but I’d like to create an embed that formats the chosen movie in a visually appealing way. I’m fairly new to using Discord.js and embeds, so I’m looking for guidance on how to integrate the random selection with creating an embed. Any advice would be much appreciated!

quick tip - move the random selection inside your if statement so it picks a new movie each time instead of reusing the same one. also don’t forget to handle the command properly or it’ll break when someone just types “movie” without the prefix.

You’ll need to use the EmbedBuilder class and wrap your random movie selection inside the embed creation. Here’s how I did it in my entertainment bot:

const { EmbedBuilder } = require('discord.js');

var movies = ["Avatar", "Inception", "Titanic", "Interstellar"];

if (message.content.startsWith(prefix + "movie")) {
    var selectedIndex = Math.floor(Math.random() * movies.length);
    
    const embed = new EmbedBuilder()
        .setTitle('🎬 Movie Recommendation')
        .addFields({ name: 'Selected Movie', value: movies[selectedIndex] })
        .setColor(0x00AE86)
        .setTimestamp();
    
    message.channel.send({ embeds: [embed] });
}

Just heads up - newer Discord.js versions use EmbedBuilder instead of MessageEmbed. The addFields method gives you cleaner formatting than just using description. You can expand this later with movie details, ratings, or thumbnails to make it more interactive.

Had the same problem building my Discord bot last year. Replace your message.channel.send() with an embed object. Import MessageEmbed from discord.js first, then create the embed with your random movie selection. Here’s what worked:

const { MessageEmbed } = require('discord.js');

var movies = ["Avatar", "Inception", "Titanic", "Interstellar"];
var selectedIndex = Math.floor(Math.random() * movies.length);

if (message.content.startsWith(prefix + "movie")) {
    const movieEmbed = new MessageEmbed()
        .setTitle('Random Movie Selection')
        .setDescription(movies[selectedIndex])
        .setColor('#0099ff');
    
    message.channel.send({ embeds: [movieEmbed] });
}

Check your Discord.js version though - the embed sending method changed in v13. Embeds give you way more flexibility for styling and adding extra movie info later.