JavaScript Embed Reply Broken

Hello, I am trying to make a embed reply but I get this error when I try to?

PS C:\\sunset lodge bot> node .
Ready!
Bot is Now Online & Working Fine
Successfully registered application commands.
TypeError: interaction.EmbedReply is not a function
    at Object.execute (C:\\commands\help.js:8:22)
    at Object.execute (C:\sunset lodge bot\events\interactionCreate.js:7:27)
    at Client.<anonymous> (C:\sunset lodge bot\index.js:22:44)
    at Client.emit (node:events:527:28)
    at InteractionCreateAction.handle (C:\sunset lodge bot\node_modules\discord.js\src\client\actions\InteractionCreate.js:74:12)
    at Object.module.exports [as INTERACTION_CREATE] (C:\sunset lodge bot\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
    at WebSocketManager.handlePacket (C:\sunset lodge bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:351:31)
    at WebSocketShard.onPacket (C:\sunset lodge bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (C:\sunset lodge bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
    at WebSocket.onMessage (C:\\sunset lodge bot\
node_modules\ws\lib\event-target.js:199:18)

Here is my code,

const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('help')
        .setDescription('A help command.'),
    async execute(interaction) {
        return interaction.EmbedReply()
        .setColor('#fff45e')
        .setTitle('Help Command!')
        .setDescription('Help Command.')
        .addField('Fun', 'Utility', 'Moderation', 'Music', 'Others')
        .addField(
            { name: 'Fun', value: 'Coming soon!', inline: false },
            { name: 'Utility', value: 'Coming soon!', inline: false },
            { name: 'Moderation', value: 'Coming soon!', inline: false },
            { name: 'Music', value: 'Coming soon!', inline: false },
            { name: 'Others', value: 'Coming soon!', inline: false },
        )
        .setTimestap()
        .setThumbnail('https://i.imgur.com/vRQOSVC')
    },
};

TypeError: interaction.EmbedReply is not a function

The error is a bit self explanatory, but as you can see “EmbedReply” is not a function.

Oh yeah, so then how do I make a embed reply with slash commands? I have searched everywhere and nothing has helped.

I don’t code in js, I’m not the best to help you in this.

However this is from the official docs: Embeds | discord.js Guide (discordjs.guide)

I see your error I think, do you import const { MessageEmbed } = require('discord.js');?

Now I’ve got this error.

C:\commands\help.js:4
        data: new SlashCommandBuilder()
                  ^

ReferenceError: SlashCommandBuilder is not defined
    at Object.<anonymous> (C:\sunset lodge bot\commands\help.js:4:12)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\sunset lodge bot\index.js:11:18)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)```

You’ve installed the packages right?

npm install @discordjs/builders

Yes.
(20 characters)

Are you on the latest version on discord.js?

Yup.
(20 characters)

Grrr, as somebody who struggles with js this may be a challenge to solve.

Can you get this to work on it’s own without any errors??

const { SlashCommandBuilder } = require('@discordjs/builders');

const data = new SlashCommandBuilder()
	.setName('help')
	.setDescription('A help command.')
client.on('interactionCreate', async interaction => {
	if (!interaction.isCommand()) return;

	if (interaction.commandName === 'help') {
		await interaction.reply('Giving help!!');
	}
});

That doesn’t work, I did this and named it test and it worked?

const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
	data: new SlashCommandBuilder()
		.setName('test')
		.setDescription('testing'),
	async execute(interaction) {
		return interaction.reply({ content: 'test', ephemeral: true });
	},
};

Great, can you change content to be an embed?

E.g:

// at the top of your file
const { MessageEmbed } = require('discord.js');

// inside a command, event listener, etc.
const exampleEmbed = new MessageEmbed()
	.setColor('#0099ff')
	.setTitle('Some title')
	.setURL('https://discord.js.org/')
	.setAuthor({ name: 'Some name', iconURL: 'https://i.imgur.com/AfFp7pu.png', url: 'https://discord.js.org' })
	.setDescription('Some description here')
	.setThumbnail('https://i.imgur.com/AfFp7pu.png')
	.addFields(
		{ name: 'Regular field title', value: 'Some value here' },
		{ name: '\u200B', value: '\u200B' },
		{ name: 'Inline field title', value: 'Some value here', inline: true },
		{ name: 'Inline field title', value: 'Some value here', inline: true },
	)
	.addField('Inline field title', 'Some value here', true)
	.setImage('https://i.imgur.com/AfFp7pu.png')
	.setTimestamp()
	.setFooter({ text: 'Some footer text here', iconURL: 'https://i.imgur.com/AfFp7pu.png' });



{ content: 'embeds: [exampleEmbed]', ephemeral: true }

That should do the trick…

Put the code in, heres the code.

// at the top of your file

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

// inside a command, event listener, etc.

const exampleEmbed = new MessageEmbed()

    .setColor('#0099ff')

    .setTitle('Some title')

    .setURL('https://discord.js.org/')

    .setAuthor({ name: 'Some name', iconURL: 'https://i.imgur.com/AfFp7pu.png', url: 'https://discord.js.org' })

    .setDescription('Some description here')

    .setThumbnail('https://i.imgur.com/AfFp7pu.png')

    .addFields(

        { name: 'Regular field title', value: 'Some value here' },

        { name: '\u200B', value: '\u200B' },

        { name: 'Inline field title', value: 'Some value here', inline: true },

        { name: 'Inline field title', value: 'Some value here', inline: true },

    )

    .addField('Inline field title', 'Some value here', true)

    .setImage('https://i.imgur.com/AfFp7pu.png')

    .setTimestamp()

    .setFooter({ text: 'Some footer text here', iconURL: 'https://i.imgur.com/AfFp7pu.png' });

({ embed: 'embeds: [exampleEmbed]', ephemeral: true });

Another flippin error, here it is.

PS C:\Users\crazy\OneDrive\Desktop\sunset lodge bot> node .
C:\Users\crazy\OneDrive\Desktop\sunset lodge bot\index.js:12
        client.commands.set(command.data.name, command);
                                         ^

TypeError: Cannot read properties of undefined (reading 'name')
    at Object.<anonymous> (C:\Users\crazy\OneDrive\Desktop\sunset lodge bot\index.js:12:35)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

Node.js v17.7.1
PS C:\Users\crazy\OneDrive\Desktop\sunset lodge bot>

That wasn’t code, that was an example, this is how it should work:

const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');

module.exports = {
	data: new SlashCommandBuilder()
		.setName('test')
		.setDescription('testing'),
	async execute(interaction) {
       const exampleEmbed = new MessageEmbed()
	    .setColor('#0099ff')
	    .setTitle('Some title')
	    .setURL('https://discord.js.org/')
	    .setAuthor({ name: 'Some name', iconURL: 'https://i.imgur.com/AfFp7pu.png', url: 'https://discord.js.org' })
	    .setDescription('Some description here')
	    .setThumbnail('https://i.imgur.com/AfFp7pu.png')
	    .addFields(
		{ name: 'Regular field title', value: 'Some value here' },
		{ name: '\u200B', value: '\u200B' },
		{ name: 'Inline field title', value: 'Some value here', inline: true },
		{ name: 'Inline field title', value: 'Some value here', inline: true },
	    )
	    . addField('Inline field title', 'Some value here', true)
	    .setImage('https://i.imgur.com/AfFp7pu.png')
	    .setTimestamp()
	    .setFooter({ text: 'Some footer text here', iconURL: 'https://i.imgur.com/AfFp7pu.png' });
       return interaction.reply({ embed: 'embeds: [exampleEmbed]', ephemeral: true });
	},
};

You may need to edit the code a bit, as I didn’t write the code in an IDE or tested it.

Now I’ve got this error :sob:

PS C:\Users\crazy\OneDrive\Desktop\sunset lodge bot> node .
Ready!
Bot is Now Online & Working Fine
Successfully registered application commands.
DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (C:\Users\crazy\OneDrive\Desktop\sunset lodge bot\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\crazy\OneDrive\Desktop\sunset lodge bot\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async CommandInteraction.reply (C:\Users\crazy\OneDrive\Desktop\sunset lodge bot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:99:5)
    at async Object.execute (C:\Users\crazy\OneDrive\Desktop\sunset lodge bot\events\interactionCreate.js:7:13) {
  method: 'post',
  path: '/interactions/970065596811202650/aW50ZXJhY3Rpb246OTcwMDY1NTk2ODExMjAyNjUwOjhWQTlMOWJXUDNaQW03VDQ4ZFZodWxWSVJRTzY5N2dJemFWdEFvaVBlNEZMelF3RUwyM3JHYjJkZmxHOVh5VzlDeURXS2I1VmtVYUQ4TFJmVGxQYkVrUng5RmI5UHJSS3JhdzYxUmVIUUFpSUlFVTB6b1duUENTS0E0ZTdHdHFN/callback',
  code: 50006,
  httpStatus: 400,
  requestData: { json: { type: 4, data: [Object] }, files: [] }
}
C:\Users\crazy\OneDrive\Desktop\sunset lodge bot\node_modules\discord.js\src\rest\RequestHandler.js:350
      throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Unknown interaction
    at RequestHandler.execute (C:\Users\crazy\OneDrive\Desktop\sunset lodge bot\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\crazy\OneDrive\Desktop\sunset lodge bot\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async CommandInteraction.reply (C:\Users\crazy\OneDrive\Desktop\sunset lodge bot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:99:5) {
  method: 'post',
  path: '/interactions/970065596811202650/aW50ZXJhY3Rpb246OTcwMDY1NTk2ODExMjAyNjUwOjhWQTlMOWJXUDNaQW03VDQ4ZFZodWxWSVJRTzY5N2dJemFWdEFvaVBlNEZMelF3RUwyM3JHYjJkZmxHOVh5VzlDeURXS2I1VmtVYUQ4TFJmVGxQYkVrUng5RmI5UHJSS3JhdzYxUmVIUUFpSUlFVTB6b1duUENTS0E0ZTdHdHFN/callback',
  code: 10062,
  httpStatus: 404,
  requestData: {
    json: {
      type: 4,
      data: {
        content: 'An error occured while trying to execute this command!',
        tts: false,
        nonce: undefined,
        embeds: undefined,
        components: undefined,
        username: undefined,
        avatar_url: undefined,
        allowed_mentions: undefined,
        flags: 64,
        message_reference: undefined,
        attachments: undefined,
        sticker_ids: undefined
      }
    },
    files: []
  }
}

Node.js v17.7.1
PS C:\Users\crazy\OneDrive\Desktop\sunset lodge bot>

What discord.js version are you on?

Get version with: npm view discord.js version

13.6.0
(20 characters)

Looks like we may have an issue with sending the embeds

Especially on this line…

Try change this to:

return interaction.reply({ embed: exampleEmbed, ephemeral: true });