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

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

Closed
Kamilake opened this issue May 31, 2023 · 2 comments
Closed

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

Kamilake opened this issue May 31, 2023 · 2 comments

Comments

@Kamilake
Copy link

Kamilake commented May 31, 2023

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?

@Kamilake Kamilake changed the title Remove or add some attachments of already sent webhooks. Edit or add some attachments of already sent webhooks. May 31, 2023
@Kamilake Kamilake changed the title Edit or add some attachments of already sent webhooks. Edit or remove some attachments of already sent webhooks. May 31, 2023
@MinnDevelopment
Copy link
Owner

I've opened #83 which should provide the necessary tools to accomplish this.

@Kamilake
Copy link
Author

Kamilake commented Jun 3, 2023

I've opened #83 which should provide the necessary tools to accomplish this.

You're spot on! That's exactly what I was looking for!

@Kamilake Kamilake closed this as completed Jun 3, 2023
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