Skip to content

Edit or remove some attachments of already sent webhooks. #82

@Kamilake

Description

@Kamilake

To add an attachment of a webhook that has already been sent, I can simply use client.edit.
But according to https://discord.com/developers/docs/resources/channel#attachment-object I need to provide a header named attachments to modify or remove existing attachments.
I provided the following headers to leave the attachment with ID '0002' in the webhook '0001' and remove all other attachments, and it worked correctly.

curl -X PATCH \
  -H "Content-Type: application/json" \
  -d '{
    "attachments": [
      {
        "id": "0002"
      }
    ]
  }' \
  'https://discord.com/api/v10/webhooks/<kamilake>/messages/0001'

The code below is my Java implementation.

public class Main {
    public static void main(String[] args) throws Throwable {
        String url = "https://discord.com/api/v10/webhooks/1234/messages/0001";
        String attachmentId = "0002";

        OkHttpClient client = new OkHttpClient();
        String json = "{\"attachments\": [{\"id\": \"" + attachmentId + "\"}]}";
        RequestBody body = RequestBody.create(json, MediaType.get("application/json; charset=utf-8"));
        Request request = new Request.Builder().url(url).patch(body).build();
        Response response = client.newCall(request).execute()
        System.out.println(response.body().string());
    }
}

I couldn't find an API that does the above operation, so I made it myself. Is that implemented in discord-webhooks?

Let me know if it exists! I'm going to fix my bot.
If not.. Shall I make one?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions