mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
fix(WebhookClient): use applyToClass instead of multiple inheritance (#1896)
This commit is contained in:
@@ -14,14 +14,16 @@ class WebhookClient extends BaseClient {
|
|||||||
* @example
|
* @example
|
||||||
* // Create a new webhook and send a message
|
* // Create a new webhook and send a message
|
||||||
* const hook = new Discord.WebhookClient('1234', 'abcdef');
|
* const hook = new Discord.WebhookClient('1234', 'abcdef');
|
||||||
* hook.sendMessage('This will send a message').catch(console.error);
|
* hook.send('This will send a message').catch(console.error);
|
||||||
*/
|
*/
|
||||||
constructor(id, token, options) {
|
constructor(id, token, options) {
|
||||||
super(options);
|
super(options);
|
||||||
Webhook.call(this, null, id, token);
|
Object.defineProperty(this, 'client', { value: this });
|
||||||
|
this.id = id;
|
||||||
|
this.token = token;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(WebhookClient.prototype, Object.create(Webhook.prototype));
|
Webhook.applyToClass(WebhookClient);
|
||||||
|
|
||||||
module.exports = WebhookClient;
|
module.exports = WebhookClient;
|
||||||
|
|||||||
@@ -8,21 +8,15 @@ const MessageEmbed = require('./MessageEmbed');
|
|||||||
* Represents a webhook.
|
* Represents a webhook.
|
||||||
*/
|
*/
|
||||||
class Webhook {
|
class Webhook {
|
||||||
constructor(client, dataOrID, token) {
|
constructor(client, data) {
|
||||||
if (client) {
|
/**
|
||||||
/**
|
* The client that instantiated the webhook
|
||||||
* The client that instantiated the webhook
|
* @name Webhook#client
|
||||||
* @name Webhook#client
|
* @type {Client}
|
||||||
* @type {Client}
|
* @readonly
|
||||||
* @readonly
|
*/
|
||||||
*/
|
Object.defineProperty(this, 'client', { value: client });
|
||||||
Object.defineProperty(this, 'client', { value: client });
|
if (data) this._patch(data);
|
||||||
if (dataOrID) this._patch(dataOrID);
|
|
||||||
} else {
|
|
||||||
this.id = dataOrID;
|
|
||||||
this.token = token;
|
|
||||||
Object.defineProperty(this, 'client', { value: this });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_patch(data) {
|
_patch(data) {
|
||||||
@@ -274,6 +268,18 @@ class Webhook {
|
|||||||
delete(reason) {
|
delete(reason) {
|
||||||
return this.client.api.webhooks(this.id, this.token).delete({ reason });
|
return this.client.api.webhooks(this.id, this.token).delete({ reason });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static applyToClass(structure) {
|
||||||
|
for (const prop of [
|
||||||
|
'send',
|
||||||
|
'sendSlackMessage',
|
||||||
|
'edit',
|
||||||
|
'delete',
|
||||||
|
]) {
|
||||||
|
Object.defineProperty(structure.prototype, prop,
|
||||||
|
Object.getOwnPropertyDescriptor(Webhook.prototype, prop));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Webhook;
|
module.exports = Webhook;
|
||||||
|
|||||||
Reference in New Issue
Block a user