Recurring "Cannot send an empty message" error

Hello, I'm intermittently getting hit with 50006 "Cannot send an empty message" errors in a production environment using discord.js. I can't seem to find any pattern aside from the fact that it occurs when sending attachments, specifically text files I've created server-side. Simply running a command multiple times will sometimes succeed and sometimes fail. Any ideas as to why this could be happening?!
70 Replies
d.js toolkit
d.js toolkit6mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
DCS - Center Founder
Hello
will
willOP6mo ago
Here is the full error:
DiscordAPIError[50006]: Cannot send an empty message
at new _DiscordAPIError (./node_modules/@discordjs/rest/dist/index.js:583:9)
at <anonymous> (./node_modules/@discordjs/rest/dist/index.js:726:111)
at processTicksAndRejections (:12:39) {
requestBody: [Object],
rawError: [Object],
code: 50006,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/channels/.../messages',
originalLine: 472,
originalColumn: 12
}
DiscordAPIError[50006]: Cannot send an empty message
at new _DiscordAPIError (./node_modules/@discordjs/rest/dist/index.js:583:9)
at <anonymous> (./node_modules/@discordjs/rest/dist/index.js:726:111)
at processTicksAndRejections (:12:39) {
requestBody: [Object],
rawError: [Object],
code: 50006,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/channels/.../messages',
originalLine: 472,
originalColumn: 12
}
The code is a bit complex and spans multiple files/functions, but in the end the important part is:
const attachments = [new AttachmentBuilder(Buffer.from(`# Before\n\n${oldContent}\n\n# After\n\n${newContent}`), {
name: `${newMessage.id}-content-changes.txt`,
description: `A file containing the content changes from the message ${newMessage.id} at ${Date.now()}`,
})];

// ...

targetChannel.fetch().then((channel) => channel.send({ embeds: [embed], files: attachments }));
const attachments = [new AttachmentBuilder(Buffer.from(`# Before\n\n${oldContent}\n\n# After\n\n${newContent}`), {
name: `${newMessage.id}-content-changes.txt`,
description: `A file containing the content changes from the message ${newMessage.id} at ${Date.now()}`,
})];

// ...

targetChannel.fetch().then((channel) => channel.send({ embeds: [embed], files: attachments }));
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
DCS - Center Founder
Hello
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
DCS - Center Founder
I'm.here to help
will
willOP6mo ago
The issue occurs without embeds as well (even if that parameter isn't provided)
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
Agreed! and this only started happening suddenly without any noticeable cause The production environment also has the same dependency and node versions
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
Dependencies:
├── @eejit/[email protected]
├── @eejit/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @eejit/[email protected]
├── @eejit/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── @types/[email protected]
Node: v22.4.1 Bun: 1.1.20 (not actually sure if that is the same in production now that I think about it) I've also tested without bufferutil and utf-8-validate, though the issue persisted
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
DCS - Center Founder
I'm here to helpppppp
will
willOP6mo ago
You could be totally right, I'll try to get the version info! You clearly aren't, please stop
DCS - Center Founder
Whatttttt
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
DCS - Center Founder
Is not really What Because you're lying I'm not doing anything to you
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
Sorry yes, meant to reply to that. There are some things that seem to make it occur like big attachments, but it doesn't always occur. It seemed like the first time it sometimes went through, and then not after that (though that wasn't always the case) It happens in many other situations, like when sending attachments copied from other messages (though that was fixed by passing the attachment.url value), and in many other scenarios with bot-generated files
DCS - Center Founder
Where is the error?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
bun appears to be at v1.1.8 in production, but I can't imagine that could be the issue
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
DCS - Center Founder
I don't know what the exact error is The only errors I can fix are 404 but in this case I don't see the not found error
will
willOP6mo ago
I have been for a few weeks, and it is all just random cases of generated text files trying to be sent with embeds. I can try to go back in the log history and check it out
monbrey
monbrey6mo ago
Please stop. If you cannot help this error (which is not a 404) then you are contributing nothing to this thread
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
I can do that, but I'm going to quickly downgrade bun on my machine to check if that could be the cause, though unlikely
DCS - Center Founder
Why you behave like this I really don't understand
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
Probably not, just grasping at straws at this point I think! I'll push a change and try to log some more errors
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
Sorry yes, misspoke, will do!
monbrey
monbrey6mo ago
The error is in the first post of the thread, and in https://discord.com/channels/222078108977594368/1262555432728264724/1262555573346500769 Are you able to help?
DCS - Center Founder
The error is 400 not 404
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
monbrey
monbrey6mo ago
Its both The HTTP status code is 400, the Discord error code is 50006 So, since you're here to help, are you able to help?
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
DCS - Center Founder
But is not 404
monbrey
monbrey6mo ago
Yes, I'm very well aware of that So you admit that you cannot help?
monbrey
monbrey6mo ago
In that case, I will again ask you to leave this thread and allow gwapes to continue helping this user
DCS - Center Founder
Bruh
will
willOP6mo ago
Here's an example: Embed:
{
title: "Message Edited",
url: undefined,
description: "@will edited a message they sent in <#950146638607958037> at <t:1721088459> at <t:1721088461>. [Jump to message](https://discord.com/channels/829686402332753940/950146638607958037/1262561249376604180)",
fields: [
{
name: "__Before__",
value: "*View in attached file*",
}, {
name: "__After__",
value: "*View in attached file*",
}
],
color: 3447003,
thumbnail: undefined,
footer: {
text: "Eejit's Tools",
icon_url: "https://raw.githubusercontent.com/Eejit43/files/main/eejit's%20tools%20(colored).png",
},
timestamp: "2024-07-16T00:07:41.224Z",
}
{
title: "Message Edited",
url: undefined,
description: "@will edited a message they sent in <#950146638607958037> at <t:1721088459> at <t:1721088461>. [Jump to message](https://discord.com/channels/829686402332753940/950146638607958037/1262561249376604180)",
fields: [
{
name: "__Before__",
value: "*View in attached file*",
}, {
name: "__After__",
value: "*View in attached file*",
}
],
color: 3447003,
thumbnail: undefined,
footer: {
text: "Eejit's Tools",
icon_url: "https://raw.githubusercontent.com/Eejit43/files/main/eejit's%20tools%20(colored).png",
},
timestamp: "2024-07-16T00:07:41.224Z",
}
Attachment:
{
attachment: {
type: "Buffer",
data: [...],
},
name: "1262561249376604180-content-changes.txt",
description: "A file containing the content changes from the message 1262561249376604180 at 1721088461224",
}
{
attachment: {
type: "Buffer",
data: [...],
},
name: "1262561249376604180-content-changes.txt",
description: "A file containing the content changes from the message 1262561249376604180 at 1721088461224",
}
I can send the whole buffer but I doubt that would be helpful
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
Yep
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
And not all the time! I just edited the message three times, it errored twice and succeeded once Which it why I just have no clue where to go from here!!!
monbrey
monbrey6mo ago
Do you have a messageUpdate listener that logs changes in content?
will
willOP6mo ago
I do, yes - sorry, should have clarified
monbrey
monbrey6mo ago
It might be trying to log the embed being rendered. The error might not be coming from this code at all?
will
willOP6mo ago
Not sure if I understand you correctly, but the embed and attachment are sent in the same message
monbrey
monbrey6mo ago
What I mean is, sending an embed actually causes Discord to fire a messageUpdate event too Or does it not send at all
will
willOP6mo ago
Ah, I see what you mean, though the listener does return if it doesn't detect a content change
monbrey
monbrey6mo ago
ahh no worries then, should already be handled
will
willOP6mo ago
Though yes, it doesn't send at all in some scenarios Yeah, I believe it is totally unrelated to the code, I think it has to be an API issue atp I've changed the code to just send the attachment, though that didn't have any effect on if the message sends successfully or not
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
Even sending one message with the embed and attachment and then another immediately after with the exact same attachment sometimes failed in either one or both cases I guess I will, and pray advaith swings by haha Thank you both for your help!! 😅
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
Will do!
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
monbrey
monbrey6mo ago
AttachmentBuilder is not async
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
monbrey
monbrey6mo ago
The AttachmentBuilder is not buffering... It can accept a Buffer as the file data
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
might not the API as I cannot reproduce it locally, but what it would be I'm not sure
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
will
willOP6mo ago
nope, still haven't heard/figured out anything :/
Want results from more Discord servers?
Add your server