Message.edit can't replace an attachment file, only adds it
Zofren opened this issue · 3 comments
Simple to describe.
I'm posting a message every 15s. This message is composed with a generated image only. I want to update the message every 15s, modifying this image with a new one.
let message = await client.getMessage(
channel_id,
message_id
);
message.edit({
file: {
file: fileBuffer,
name: "thename.png"
},
});
Expected : the generated images are replaced by the newer one every 15s.
Result : the generated images are stacking in the edited message every 15s until I reach the attachment limit.
Workaround : every 15s, I clean the channel and post a new message with the new generated image. It's not visually satisfying.
Among other things, #1285 documents the attachments
field, which is used to control which attachments remain present on the message after editing. The field should be usable in the current version if you pass it to edit
and refer to Discord's docs on how to use it.
Without using attachments
, the observed behavior is expected.
https://discord.com/developers/docs/resources/channel#edit-message
... Any provided files will be appended to the message. To remove or replace files you will have to supply the
attachments
field which specifies the files to retain on the message after edit.
Problem is I sent the image as an image Buffer. When using attachments, I can't see how I can send it that way. It requires a filename, a path that doesn't exist yet.
Resolved with
message.edit({
attachments: [],
file: file,
});
Thank you !