Open Bruno-Marley opened 3 years ago
getting same error
This also happened to me when I tried passing a value to .setTimestamp()
.
I found that using something like let embed = new MessageBuilder();
and then embed.setURL(aUrlStringThatIsNotEmpty);
meant that the embed
object was empty and setURL
did not actually add to the object. This meant the result would be 400 since all of the methods (except addTitle(titleString)
) to add to the object did not seem to add.
Just came across this now and found when the payload for an embed is being built if the value used is undefined
or empty string then the value in the field object is not set which causes the 400 code.
const wh = new Webhook(whUrl);
const embed = new MessageBuilder()
.setTitle('Test')
.addField('Email', undefined, true)
.setColor('#FF0000')
.setTimestamp();
Code above will result in a payload like this where there is no value for the Email
field:
{
"embeds": [
{
"fields": [{ "name": "Email", "inline": true }],
"title": "Test",
"color": 15142414,
"timestamp": "2022-12-08T22:16:44.216Z"
}
]
}
This also happened to me when I tried passing a value to
.setTimestamp()
.
Over a year later I'm finally tired of working around this libraries pitfalls (#25 for example), so I forked and rewrote the entire thing. It's called Hookr, still a bit of a WIP (file uploads may not work, haven't tested them) but overall is compliant with Discords API and can send multiple embeds per message, which this library cannot.
Iam trying to send a simple embed with this package and it's gives me a error
Error sending webhook: 400 status code. Response: {"embeds": ["0"]}
Any idea how I can resolve this?