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

Can't edit message sent through Webhook #5377

Closed
Protected opened this issue Mar 8, 2021 · 8 comments · Fixed by #5223
Closed

Can't edit message sent through Webhook #5377

Protected opened this issue Mar 8, 2021 · 8 comments · Fixed by #5223

Comments

@Protected
Copy link

Protected commented Mar 8, 2021

Please describe the problem you are having in as much detail as possible:

According to the documentation, Webhook.send returns an instance of Message, which has an edit method. However, when I attempt to use the edit method, the following error is thrown:

(node:1984) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot edit a message authored by another user
    at RequestHandler.execute (...)

The API allows editing webhook messages: https://discord.com/developers/docs/resources/webhook#edit-webhook-message

And the Message object knows its webhookID, so the intuitive behavior here would be for the edit to be sent through the webhook.

Include a reproducible code sample here, if possible:

//Given client, id_webhook
let webhook = await client.fetchWebhook(id_webhook);
let message = await webhook.send("world", {username: "hello"});
message.edit("moon");

Further details:

  • discord.js version: 12.5.1
  • Node.js version: 14.15.4
  • Operating system: Windows 10
  • Priority this issue should have – please be realistic and elaborate if possible: Medium
@tipakA
Copy link
Contributor

tipakA commented Mar 8, 2021

#5223 is not merged yet, and even if it will get merged, it will most likely not land in any release before v13

@Protected
Copy link
Author

My repository search didn't bring that up, but I'm glad to know it's coming.

@SpaceEEC SpaceEEC linked a pull request Mar 8, 2021 that will close this issue
5 tasks
@saahil-sutaria
Copy link

@almostSouji @tipakA @millette I am a Full-Stack Software Engineer from the SF bay area. This is my first time contributing to open source and I am very excited to play my part. I can work on this enhancement. I have everything set up that includes discord bot, forked repo, and all that stuff. Any tips for me are most welcome!

@tipakA
Copy link
Contributor

tipakA commented Mar 21, 2021

But... the enhancement is already created. Just not merged, and not released

@saahil-sutaria
Copy link

Got it! @tipakA Can I have some other issue to work with? A small bug or maybe a feature enhancement

@Protected
Copy link
Author

I just tested in master and Message.edit still throws the obscure Cannot edit a message authored by another user when an attempt is made to use Message.edit on a message generated by a webhook. I see Webhook.editMessage, but is there a particular reason why Message.edit can't transparently use Webhook.editMessage when Message knows it belongs to a webhook?

@advaith1
Copy link
Contributor

advaith1 commented Apr 7, 2021

webhooks aren't cached so it wouldn't know the wwbhook's token

@tipakA
Copy link
Contributor

tipakA commented Apr 7, 2021

@Protected Well, from where exactly would library take info necessary to operate a webhook? Sure, if the message you are trying to edit was sent by a webhook, it will have webhookID property populated, but this is not everything that is needed to interact as that webhook.
To actually be able to operate a webhook, you need a token. Only way to obtain a token for a webhook is to fetch the webhook with Client#fetchWebhook() or TextChannel#fetchWebhooks(), but doing so requires MANAGE_WEBHOOKS permission, invalidating on spot any reasoning for the library to perform such fetch under the hood in order to get the token it could use to edit the message (where such "hidden" fetch already would be strongly argued against).

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants