mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
feat(Webhook): add type property and created* getters (#3585)
* feat(Webhook): add created* getters * feat(Webhook): add type property * typings(WebhookFields): use primitive string for url getter Co-Authored-By: Gryffon Bellish <owenbellish@gmail.com> * fix(Webhook): token can be null Co-authored-by: Gryffon Bellish <owenbellish@gmail.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const { WebhookTypes } = require('../util/Constants');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const Snowflake = require('../util/Snowflake');
|
||||
const Channel = require('./Channel');
|
||||
const APIMessage = require('./APIMessage');
|
||||
|
||||
@@ -29,9 +31,9 @@ class Webhook {
|
||||
/**
|
||||
* The token for the webhook
|
||||
* @name Webhook#token
|
||||
* @type {string}
|
||||
* @type {?string}
|
||||
*/
|
||||
Object.defineProperty(this, 'token', { value: data.token, writable: true, configurable: true });
|
||||
Object.defineProperty(this, 'token', { value: data.token || null, writable: true, configurable: true });
|
||||
|
||||
/**
|
||||
* The avatar for the webhook
|
||||
@@ -45,6 +47,12 @@ class Webhook {
|
||||
*/
|
||||
this.id = data.id;
|
||||
|
||||
/**
|
||||
* The type of the webhook
|
||||
* @type {WebhookTypes}
|
||||
*/
|
||||
this.type = WebhookTypes[data.type];
|
||||
|
||||
/**
|
||||
* The guild the webhook belongs to
|
||||
* @type {Snowflake}
|
||||
@@ -210,6 +218,23 @@ class Webhook {
|
||||
delete(reason) {
|
||||
return this.client.api.webhooks(this.id, this.token).delete({ reason });
|
||||
}
|
||||
/**
|
||||
* The timestamp the webhook was created at
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get createdTimestamp() {
|
||||
return Snowflake.deconstruct(this.id).timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* The time the webhook was created at
|
||||
* @type {Date}
|
||||
* @readonly
|
||||
*/
|
||||
get createdAt() {
|
||||
return new Date(this.createdTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* The url of this webhook
|
||||
@@ -236,6 +261,9 @@ class Webhook {
|
||||
'sendSlackMessage',
|
||||
'edit',
|
||||
'delete',
|
||||
'createdTimestamp',
|
||||
'createdAt',
|
||||
'url',
|
||||
]) {
|
||||
Object.defineProperty(structure.prototype, prop,
|
||||
Object.getOwnPropertyDescriptor(Webhook.prototype, prop));
|
||||
|
||||
Reference in New Issue
Block a user