luke
April 30, 2022, 9:31am
1
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')
},
};
cookie
April 30, 2022, 2:45pm
2
TypeError: interaction.EmbedReply is not a function
The error is a bit self explanatory, but as you can see “EmbedReply” is not a function.
luke
April 30, 2022, 3:51pm
3
Oh yeah, so then how do I make a embed reply with slash commands? I have searched everywhere and nothing has helped.
cookie
April 30, 2022, 7:45pm
4
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)
cookie
April 30, 2022, 7:46pm
5
I see your error I think, do you import const { MessageEmbed } = require('discord.js');
?
luke
April 30, 2022, 7:48pm
6
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)```
cookie
April 30, 2022, 7:50pm
7
You’ve installed the packages right?
npm install @discordjs/builders
cookie
April 30, 2022, 8:15pm
9
Are you on the latest version on discord.js?
cookie
April 30, 2022, 8:25pm
11
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!!');
}
});
luke
April 30, 2022, 8:28pm
12
cookie:
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 });
},
};
cookie
April 30, 2022, 8:36pm
13
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…
luke
April 30, 2022, 8:44pm
15
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>
cookie
April 30, 2022, 8:51pm
16
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.
luke
April 30, 2022, 8:55pm
17
Now I’ve got this error
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>
cookie
April 30, 2022, 9:03pm
18
What discord.js
version are you on?
Get version with: npm view discord.js version
cookie
April 30, 2022, 9:07pm
20
Looks like we may have an issue with sending the embeds
Especially on this line…
cookie
April 30, 2022, 9:09pm
21
Try change this to:
return interaction.reply({ embed: exampleEmbed, ephemeral: true });