Reputation: 204
I am currently trying to script that when a person sends a message to a specific channel, that message is then automatically converted to an embed. For me the conversion works the first time but not the second time. I'm always getting an error after the messages was converted.
My Script:
const channel = "905504402276765766";
if(channel.includes(message.channel.id))
var test = message.content.slice(" ")
const tryembed = new Discord.MessageEmbed()
.setColor('DARK_RED')
.setTitle('Test')
.addFields(
{name: "Person who wants to report a bug:", value: `<@!${message.author.id}>`},
{name: "Bug that was reported:", value: test}
)
message.channel.send({embeds: [tryembed]})
message.delete()
My error Code:
C:\Discord Bots\Bot v13\node_modules\discord.js\src\util\Util.js:414
if (!allowEmpty && data.length === 0) throw new error(errorMessage);
^
RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.
at Function.verifyString (C:\Discord Bots\Bot v13\node_modules\discord.js\src\util\Util.js:414:49)
at Function.normalizeField (C:\Discord Bots\Bot v13\node_modules\discord.js\src\structures\MessageEmbed.js:441:19)
at C:\Discord Bots\Bot v13\node_modules\discord.js\src\structures\MessageEmbed.js:462:14
at Array.map (<anonymous>)
at Function.normalizeFields (C:\Discord Bots\Bot v13\node_modules\discord.js\src\structures\MessageEmbed.js:461:8)
at MessageEmbed.addFields (C:\Discord Bots\Bot v13\node_modules\discord.js\src\structures\MessageEmbed.js:283:42)
at Client.<anonymous> (C:\Discord Bots\Bot v13\index.js:44:2)
at Client.emit (node:events:394:28)
at MessageCreateAction.handle (C:\Discord Bots\Bot v13\node_modules\discord.js\src\client\actions\MessageCreate.js:23:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Discord Bots\Bot v13\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32) {
[Symbol(code)]: 'EMBED_FIELD_VALUE'
}
Upvotes: 1
Views: 320
Reputation: 2208
Using value: `** ** ${test}`
will solve your problem, so you need to change your {name: "Bug that was reported:", value: test}
to:
{name: "Bug that was reported:", value: `** ** ${test}`}
Upvotes: 1