Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message.edit can't replace an attachment file, only adds it #1417

Closed
Zofren opened this issue Sep 4, 2022 · 3 comments
Closed

Message.edit can't replace an attachment file, only adds it #1417

Zofren opened this issue Sep 4, 2022 · 3 comments

Comments

@Zofren
Copy link

Zofren commented Sep 4, 2022

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.

@eritbh
Copy link
Contributor

eritbh commented Sep 4, 2022

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.

@Zofren
Copy link
Author

Zofren commented Sep 4, 2022

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.

@Zofren
Copy link
Author

Zofren commented Sep 4, 2022

Resolved with

 message.edit({
      attachments: [],
      file: file,
    });

Thank you !

@Zofren Zofren closed this as completed Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants