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?
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
attachmentsto 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.
The code below is my Java implementation.
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?