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

webhook#send throws DiscordAPIError: 405: Method Not Allowed #5731

Closed
dallastjames opened this issue Jun 2, 2021 · 4 comments · Fixed by #5798
Closed

webhook#send throws DiscordAPIError: 405: Method Not Allowed #5731

dallastjames opened this issue Jun 2, 2021 · 4 comments · Fixed by #5798

Comments

@dallastjames
Copy link

dallastjames commented Jun 2, 2021

In the last 2 days or so, I've started seeing errors pop up in my deployed bot instance when attempting to send messages via a fetched webhook. This code has been deployed for over a month plus, so my assumption is that perhaps something may have changed with the Discord API itself (at the time of writing, no reports on their status page). I've spent some time digging into this, and it looks like the request message that is being sent to the api is in the format POST api/webhooks/webhookId, when based on the documentation, it should be POST api/webhooks/webhookId/webhookToken. When adding the token to the request url that is failing, it does function as expected.

This was tested by overriding the URL provided in APIRequest.js to include the token on the url to match the documentation.

Continuing to dive further, I was able to determine in my test application that this.token in the Webhook.js code was never being set. Tracking back up the tree, I found Client#fetchWebhook, which is what is being used to look up the webhook information. Looking at the data response here, it looks as though Discord is not returning the token associated with the webhook in the data payload, resulting in the further failures. Checking this, even though the token is supposed to be returned for the Incoming Webhook data type, for some reason that is no longer the case.

I was able to verify this by using my webhook ID and token to hit the discord API directly and see that the token is no longer found in the response

The easiest resolution in this case is to patch the data object returned from the API to include to the token which is already accessible to the fetchWebhook method, though that may very well not be the best solution.

Reproduction

https://github.com/dallastjames/discordjs-webhook-send-error

Further details:

  • discord.js version: latest (12.5.3)
  • Node.js version: 14.16.1
  • Operating system: alpine linux, wsl2
  • Priority this issue should have – High, webhook lookup then send functionality is broken for existing code

Relevant client options:

  • partials: none
  • gateway intents: none
  • other: none
@UltimateBrent
Copy link

I'm having similar issues. Any hacky workarounds I could implement in the meantime?

@dallastjames
Copy link
Author

dallastjames commented Jun 2, 2021

@UltimateBrent for my application, I directly edited node_modules/discord.js/src/client/Client.js lines 289-294 (fetchWebhook) to be

fetchWebhook(id, token) {
    return this.api
      .webhooks(id, token)
      .get()
      .then(data => new Webhook(this, {...data, token})); // <-- the second param here
  }

This re-attaches the token to the webhook payload as it should be based on the api docs, and then everything else works as expected. Obviously, editing the compiled code directly in node_modules isn't a scalable solution, but for me it'll work until an actual fix can be implemented.

@Darqam
Copy link
Contributor

Darqam commented Jun 2, 2021

To quote an answer from a discord dev posted in the server a few minutes ago
https://github.com/discordjs/discord.js/issues/5731 is a bug in discord should be fixed soon

So this does not sound like something that djs should be trying to fix.

@dallastjames
Copy link
Author

@Darqam awesome, that's totally acceptable to me. I figure those working on this library have more "insider knowledge" in terms of bugs with the Discord API than I would. In that case, at least the hacky workaround above will hold me over until Discord is able to address the issue at hand.

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.

4 participants