imallett
imallett
DIAdiscord.js - Imagine an app
Created by imallett on 11/3/2023 in #djs-questions
Re-sending Embed Unmodified Nevertheless Changes Its Appearance Significantly
If I copy an embed from one message and attach it to a new message (something like this):
webhook.send({ embeds:[Discord.EmbedBuilder.from(message.embed)] });
webhook.send({ embeds:[Discord.EmbedBuilder.from(message.embed)] });
I would expect to get something that looks the same out. However, the embed often differs drastically, generally getting smaller and with less information. For example: - Twitter (fxtwitter) embeds move photos into a thumbnail and reshuffle fields - Github embeds lose the title and opengraph summary image - YouTube embeds get a thumbnail but lose the ability to actually play the video - Google Docs embeds lose the title - Wikipedia embeds move images to thumbnails The consistent shrinkage feels like it's trying to be a feature, but it should not be the default behavior, and anyway in this case I need the embeds to be identical to the originals if possible. In the previous version of my bot, I was so desperate for that behavior, I resorted to recreating each embed from scratch as best I could. This is obviously horrendous, and ultimately a losing battle, not a solution. How can I control this properly?
4 replies
DIAdiscord.js - Imagine an app
Created by imallett on 11/3/2023 in #djs-questions
Reordering Embeds and Attachments in a Message
As far as I can tell, Discord orders posts as (1) text, (2) all attachments, (3) all embeds. What I'd really like is to have instead is one embed, then all attachments, then the rest of the embeds. I assume this isn't possible. Can I get a confirmation or refutation?
6 replies
DIAdiscord.js - Imagine an app
Created by imallett on 11/2/2023 in #djs-questions
"ERR_INVALID_STATE" "Writer has been released" when trying to repost an attachment
I am trying to take a Message's .attachments and "repost" them attached to a new message (sent via webhook, if it matters). Upon sending, however, I get an error from deep inside the library:
TypeError [ERR_INVALID_STATE]: Invalid state: Writer has been released
(at lazyWritableReleasedError (node:internal/webstreams/writablestream:94:19)
TypeError [ERR_INVALID_STATE]: Invalid state: Writer has been released
(at lazyWritableReleasedError (node:internal/webstreams/writablestream:94:19)
The code is something like:
mywebhook.send({
embeds: Array.from( some_message.embeds, embed=>Discord.EmbedBuilder.from(embed) ),
files: Array.from( some_message.attachments.values() )
});
mywebhook.send({
embeds: Array.from( some_message.embeds, embed=>Discord.EmbedBuilder.from(embed) ),
files: Array.from( some_message.attachments.values() )
});
with no content: needed in this use-case. Note that the code works perfectly when there are no attachments. My guess is some sort of internal write-stream state is being stored somewhere and it doesn't like the attachments being reused. Against that possibility, by analogy with the embeds, I did variations on stuff like:
files: Array.from(
some_message.attachments.values(),
attachment => new Discord.AttachmentBuilder( attachment.url )
)
files: Array.from(
some_message.attachments.values(),
attachment => new Discord.AttachmentBuilder( attachment.url )
)
to no avail. The documentation has no guidance on this, and the error has evidently been reported nowhere, so I'm really just guessing at this point. What approach should I be doing? Thanks.
12 replies