How do I add fields to message embed objects?

I have this code: https://srcb.in/nDh1ScQ8Oz I am trying to do report2.addField and it isn't working. It is saying
bot/commands/reports/report.js:61
report2.addField([{ name: 'Message ID', value: `\`${reportNo}\`` }]);
^

TypeError: report2.addField is not a function
at Object.execute (/root/bot/commands/reports/report.js:61:17)
bot/commands/reports/report.js:61
report2.addField([{ name: 'Message ID', value: `\`${reportNo}\`` }]);
^

TypeError: report2.addField is not a function
at Object.execute (/root/bot/commands/reports/report.js:61:17)
I have no idea why.
18 Replies
Jaworek
Jaworek3y ago
what is report2
Erin
ErinOP3y ago
const report2 = {
color: '#11818C',
title: `Your report has been sent to ${me.name} aka ${me.username}!`,
author: {
name: authorUsername,
icon_url: avatar
},
thumbnail: {
url: avatar
},
description: `**This is the report:**\n${description}\n\n**Any files uploaded?**\n${url}`,
timestamp: new Date(),
footer: {
text: 'This was all of the info I could grab from the report.',
icon_url: bot.avatar
}
}
const report2 = {
color: '#11818C',
title: `Your report has been sent to ${me.name} aka ${me.username}!`,
author: {
name: authorUsername,
icon_url: avatar
},
thumbnail: {
url: avatar
},
description: `**This is the report:**\n${description}\n\n**Any files uploaded?**\n${url}`,
timestamp: new Date(),
footer: {
text: 'This was all of the info I could grab from the report.',
icon_url: bot.avatar
}
}
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Jaworek
Jaworek3y ago
its object not class monbreyFacepalm
Erin
ErinOP3y ago
Alright so If I want to do this I have to do new MessageEmbed() right?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Jaworek
Jaworek3y ago
btw addField except objrct not array ( u mean addFields) look at tags v13 not v14
d.js docs
d.js docs3y ago
class MessageEmbed Represents an embed in a message (image/video preview, rich embed, etc.)
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Jaworek
Jaworek3y ago
main is v14 #djs-in-dev-version stable v13
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
chewie
chewie3y ago
stable is still outdated
Erin
ErinOP3y ago
Okay, so I am having issues with this line now: const url = message.attachments.first().url || 'no'; It either passes the URL (if it is first like this) or if I have it like this const url = 'no' || message.attachments.first().url; It only passes no it is like the OR || is not working. Do I need to use an if statement instead?
Jaworek
Jaworek3y ago
'no' is true so it alwys be also .first().url will make error if .first() is undefined
Erin
ErinOP3y ago
Yeah, so if there isn't an attachment I want url to be no if there is I want it to have the attachment's URL Using an IF statment doesn't work.
d.js docs
d.js docs3y ago
mdn Optional chaining (?.) The optional chaining operator (?.) enables you to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid.
Jaworek
Jaworek3y ago
just add it after .first() and it should work
Erin
ErinOP3y ago
I knew I was missing something. Thank you!
Want results from more Discord servers?
Add your server