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

feat: Allow webhooks to fetch, edit and delete messages in threads #6695

Merged
merged 10 commits into from Oct 2, 2021

Conversation

Jiralite
Copy link
Member

Please describe the changes this PR makes and why it should be merged:
This will allow webhooks to fetch, edit and delete messages in threads.

Webhook#fetchMessage() unfortunately didn't already have an object for its second parameter. I would have liked to change it to what I commented here but to keep it not breaking, I instead added a new client option for webhooks that as a sort of opt-in feature flag that makes the library parse the second parameter as an object, thus allowing access to fetching a message in a thread.

Here's an example:

const { WebhookClient } = require("discord.js");

const webhook1 = new WebhookClient({
  url: "webhook_url1"
});

const webhook2 = new WebhookClient({
  url: "webhook_url2"
}, {
  allowWebhookThreadFetching: true // With this enabled, I can now fetch messages in threads!
});

webhook1.fetchMessage("message_id1", false).then(console.log); // Success!
// No error or change in code as we did not opt-in to fetching in threads. Parameter is unchanged.

webhook2.fetchMessage("message_id2", {
  cache: false,
  threadId: "thread_id"
}).then(console.log); // Success!

This should resolve #6592, additional. I am open to adjustments and feedback!

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating
  • This PR changes the library's interface (methods or parameters added)

src/structures/Webhook.js Outdated Show resolved Hide resolved
@monbrey
Copy link
Member

monbrey commented Sep 26, 2021

What's the point of the client option? Why would we ever NOT want to allow this?

EDIT: Okay, I missed the reason in your post, I see it now. Not a fan of that solution, its extremely monkey-patched.

@Jiralite
Copy link
Member Author

I have gone with @ckohen's desired approach. Feel free to re-review!

src/structures/Webhook.js Outdated Show resolved Hide resolved
typings/index.d.ts Outdated Show resolved Hide resolved
src/structures/Webhook.js Outdated Show resolved Hide resolved
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
@iCrawl iCrawl merged commit 107822d into discordjs:main Oct 2, 2021
@Jiralite Jiralite deleted the webhook-thread branch October 2, 2021 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Webhook.editMessage() into a thread doesn't work
7 participants