feat(Webhook): add ability to change channel and specify reason to edit (#3587)

* feat(Webhook): add ability to change channel and specify reason to edit

* fix(RESTMethods): update channelID of the webhook too
This commit is contained in:
SpaceEEC
2020-01-05 18:34:00 +01:00
committed by GitHub
parent d1d0d75d4a
commit fbe9bc499b
3 changed files with 58 additions and 14 deletions

View File

@@ -801,13 +801,23 @@ class RESTMethods {
.then(data => new Webhook(this.client, data));
}
editWebhook(webhook, name, avatar) {
return this.rest.makeRequest('patch', Endpoints.Webhook(webhook.id, webhook.token), false, {
name,
avatar,
}).then(data => {
editWebhook(webhook, options, reason) {
let endpoint;
let auth;
// Changing the channel of a webhook or specifying a reason requires a bot token
if (options.channel_id || reason) {
endpoint = Endpoints.Webhook(webhook.id);
auth = true;
} else {
endpoint = Endpoints.Webhook(webhook.id, webhook.token);
auth = false;
}
return this.rest.makeRequest('patch', endpoint, auth, options, undefined, reason).then(data => {
webhook.name = data.name;
webhook.avatar = data.avatar;
webhook.channelID = data.channel_id;
return webhook;
});
}