From c05faaef7f4370441cefa14238bc757b8bd7d608 Mon Sep 17 00:00:00 2001
From: MrMythical <91077061+MrMythicalYT@users.noreply.github.com>
Date: Fri, 4 Nov 2022 19:54:10 -0400
Subject: [PATCH 1/5] feat(Webhook): add `channel` property
---
packages/discord.js/src/structures/Webhook.js | 11 +++++++++--
packages/discord.js/typings/index.d.ts | 1 +
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/packages/discord.js/src/structures/Webhook.js b/packages/discord.js/src/structures/Webhook.js
index e6eccaed4134..055b2dfcf75b 100644
--- a/packages/discord.js/src/structures/Webhook.js
+++ b/packages/discord.js/src/structures/Webhook.js
@@ -73,7 +73,7 @@ class Webhook {
if ('channel_id' in data) {
/**
- * The channel the webhook belongs to
+ * The id of the channel the webhook belongs to
* @type {Snowflake}
*/
this.channelId = data.channel_id;
@@ -140,7 +140,14 @@ class Webhook {
* @property {Snowflake} [threadId] The id of the thread this message belongs to
* For interaction webhooks, this property is ignored
*/
-
+ /**
+ * The channel that this webhook belongs to
+ * @type {?GuildTextBasedChannel}
+ * @readonly
+ */
+ get channel() {
+ return this.client.channels.resolve(this.channelId);
+ }
/**
* Sends a message with this webhook.
* @param {string|MessagePayload|WebhookCreateMessageOptions} options The options to provide
diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts
index e2586331a58d..f4f6e05df705 100644
--- a/packages/discord.js/typings/index.d.ts
+++ b/packages/discord.js/typings/index.d.ts
@@ -2908,6 +2908,7 @@ export class Webhook extends WebhookMixin() {
public token: string | null;
public type: WebhookType;
public applicationId: Snowflake | null;
+ public get channel(): GuildTextBasedChannel | null;
public isUserCreated(): this is this & {
type: WebhookType.Incoming;
applicationId: null;
From 5c018cd1ea36df4ebfe3aa20dee037404a827fef Mon Sep 17 00:00:00 2001
From: MrMythical <91077061+MrMythicalYT@users.noreply.github.com>
Date: Fri, 4 Nov 2022 20:06:20 -0400
Subject: [PATCH 2/5] fix: allow ForumChannel type
---
packages/discord.js/src/structures/Webhook.js | 2 +-
packages/discord.js/typings/index.d.ts | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/packages/discord.js/src/structures/Webhook.js b/packages/discord.js/src/structures/Webhook.js
index 055b2dfcf75b..c9b5bbd1e79e 100644
--- a/packages/discord.js/src/structures/Webhook.js
+++ b/packages/discord.js/src/structures/Webhook.js
@@ -142,7 +142,7 @@ class Webhook {
*/
/**
* The channel that this webhook belongs to
- * @type {?GuildTextBasedChannel}
+ * @type {?(GuildTextBasedChannel|ForumChannel)}
* @readonly
*/
get channel() {
diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts
index f4f6e05df705..f0f94e8dcffc 100644
--- a/packages/discord.js/typings/index.d.ts
+++ b/packages/discord.js/typings/index.d.ts
@@ -2908,7 +2908,7 @@ export class Webhook extends WebhookMixin() {
public token: string | null;
public type: WebhookType;
public applicationId: Snowflake | null;
- public get channel(): GuildTextBasedChannel | null;
+ public get channel(): GuildTextBasedChannel | ForumChannel | null;
public isUserCreated(): this is this & {
type: WebhookType.Incoming;
applicationId: null;
From acaedb8aeb83b500ae7c6d43391b8b12b1f7b17d Mon Sep 17 00:00:00 2001
From: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com>
Date: Fri, 4 Nov 2022 22:24:53 -0400
Subject: [PATCH 3/5] fix: disallow thread channel type
---
packages/discord.js/src/structures/Webhook.js | 187 +++++++++++-------
packages/discord.js/typings/index.d.ts | 2 +-
2 files changed, 121 insertions(+), 68 deletions(-)
diff --git a/packages/discord.js/src/structures/Webhook.js b/packages/discord.js/src/structures/Webhook.js
index c9b5bbd1e79e..ef2a19e350cb 100644
--- a/packages/discord.js/src/structures/Webhook.js
+++ b/packages/discord.js/src/structures/Webhook.js
@@ -1,14 +1,14 @@
-'use strict';
+"use strict";
-const { makeURLSearchParams } = require('@discordjs/rest');
-const { lazy } = require('@discordjs/util');
-const { DiscordSnowflake } = require('@sapphire/snowflake');
-const { Routes, WebhookType } = require('discord-api-types/v10');
-const MessagePayload = require('./MessagePayload');
-const { DiscordjsError, ErrorCodes } = require('../errors');
-const DataResolver = require('../util/DataResolver');
+const { makeURLSearchParams } = require("@discordjs/rest");
+const { lazy } = require("@discordjs/util");
+const { DiscordSnowflake } = require("@sapphire/snowflake");
+const { Routes, WebhookType } = require("discord-api-types/v10");
+const MessagePayload = require("./MessagePayload");
+const { DiscordjsError, ErrorCodes } = require("../errors");
+const DataResolver = require("../util/DataResolver");
-const getMessage = lazy(() => require('./Message').Message);
+const getMessage = lazy(() => require("./Message").Message);
/**
* Represents a webhook.
@@ -21,12 +21,12 @@ class Webhook {
* @type {Client}
* @readonly
*/
- Object.defineProperty(this, 'client', { value: client });
+ Object.defineProperty(this, "client", { value: client });
if (data) this._patch(data);
}
_patch(data) {
- if ('name' in data) {
+ if ("name" in data) {
/**
* The name of the webhook
* @type {string}
@@ -39,9 +39,13 @@ class Webhook {
* @name Webhook#token
* @type {?string}
*/
- Object.defineProperty(this, 'token', { value: data.token ?? null, writable: true, configurable: true });
+ Object.defineProperty(this, "token", {
+ value: data.token ?? null,
+ writable: true,
+ configurable: true,
+ });
- if ('avatar' in data) {
+ if ("avatar" in data) {
/**
* The avatar for the webhook
* @type {?string}
@@ -55,7 +59,7 @@ class Webhook {
*/
this.id = data.id;
- if ('type' in data) {
+ if ("type" in data) {
/**
* The type of the webhook
* @type {WebhookType}
@@ -63,7 +67,7 @@ class Webhook {
this.type = data.type;
}
- if ('guild_id' in data) {
+ if ("guild_id" in data) {
/**
* The guild the webhook belongs to
* @type {Snowflake}
@@ -71,7 +75,7 @@ class Webhook {
this.guildId = data.guild_id;
}
- if ('channel_id' in data) {
+ if ("channel_id" in data) {
/**
* The id of the channel the webhook belongs to
* @type {Snowflake}
@@ -79,7 +83,7 @@ class Webhook {
this.channelId = data.channel_id;
}
- if ('user' in data) {
+ if ("user" in data) {
/**
* The owner of the webhook
* @type {?(User|APIUser)}
@@ -89,7 +93,7 @@ class Webhook {
this.owner ??= null;
}
- if ('application_id' in data) {
+ if ("application_id" in data) {
/**
* The application that created this webhook
* @type {?Snowflake}
@@ -99,22 +103,25 @@ class Webhook {
this.applicationId ??= null;
}
- if ('source_guild' in data) {
+ if ("source_guild" in data) {
/**
* The source guild of the webhook
* @type {?(Guild|APIGuild)}
*/
- this.sourceGuild = this.client.guilds?.resolve(data.source_guild.id) ?? data.source_guild;
+ this.sourceGuild =
+ this.client.guilds?.resolve(data.source_guild.id) ?? data.source_guild;
} else {
this.sourceGuild ??= null;
}
- if ('source_channel' in data) {
+ if ("source_channel" in data) {
/**
* The source channel of the webhook
* @type {?(NewsChannel|APIChannel)}
*/
- this.sourceChannel = this.client.channels?.resolve(data.source_channel?.id) ?? data.source_channel;
+ this.sourceChannel =
+ this.client.channels?.resolve(data.source_channel?.id) ??
+ data.source_channel;
} else {
this.sourceChannel ??= null;
}
@@ -142,7 +149,7 @@ class Webhook {
*/
/**
* The channel that this webhook belongs to
- * @type {?(GuildTextBasedChannel|ForumChannel)}
+ * @type {?(TextChannel|VoiceChannel|NewsChannel|ForumChannel)}
* @readonly
*/
get channel() {
@@ -197,7 +204,8 @@ class Webhook {
* .catch(console.error);
*/
async send(options) {
- if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
+ if (!this.token)
+ throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
let messagePayload;
@@ -213,10 +221,18 @@ class Webhook {
});
const { body, files } = await messagePayload.resolveFiles();
- const d = await this.client.rest.post(Routes.webhook(this.id, this.token), { body, files, query, auth: false });
+ const d = await this.client.rest.post(Routes.webhook(this.id, this.token), {
+ body,
+ files,
+ query,
+ auth: false,
+ });
if (!this.client.channels) return d;
- return this.client.channels.cache.get(d.channel_id)?.messages._add(d, false) ?? new (getMessage())(this.client, d);
+ return (
+ this.client.channels.cache.get(d.channel_id)?.messages._add(d, false) ??
+ new (getMessage())(this.client, d)
+ );
}
/**
@@ -238,14 +254,18 @@ class Webhook {
* @see {@link https://api.slack.com/messaging/webhooks}
*/
async sendSlackMessage(body) {
- if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
+ if (!this.token)
+ throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
- const data = await this.client.rest.post(Routes.webhookPlatform(this.id, this.token, 'slack'), {
- query: makeURLSearchParams({ wait: true }),
- auth: false,
- body,
- });
- return data.toString() === 'ok';
+ const data = await this.client.rest.post(
+ Routes.webhookPlatform(this.id, this.token, "slack"),
+ {
+ query: makeURLSearchParams({ wait: true }),
+ auth: false,
+ body,
+ }
+ );
+ return data.toString() === "ok";
}
/**
@@ -263,15 +283,18 @@ class Webhook {
* @returns {Promise}
*/
async edit({ name = this.name, avatar, channel, reason }) {
- if (avatar && !(typeof avatar === 'string' && avatar.startsWith('data:'))) {
+ if (avatar && !(typeof avatar === "string" && avatar.startsWith("data:"))) {
avatar = await DataResolver.resolveImage(avatar);
}
channel &&= channel.id ?? channel;
- const data = await this.client.rest.patch(Routes.webhook(this.id, channel ? undefined : this.token), {
- body: { name, avatar, channel_id: channel },
- reason,
- auth: !this.token || Boolean(channel),
- });
+ const data = await this.client.rest.patch(
+ Routes.webhook(this.id, channel ? undefined : this.token),
+ {
+ body: { name, avatar, channel_id: channel },
+ reason,
+ auth: !this.token || Boolean(channel),
+ }
+ );
this.name = data.name;
this.avatar = data.avatar;
@@ -294,17 +317,24 @@ class Webhook {
* @returns {Promise} Returns the message sent by this webhook
*/
async fetchMessage(message, { threadId } = {}) {
- if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
+ if (!this.token)
+ throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
- const data = await this.client.rest.get(Routes.webhookMessage(this.id, this.token, message), {
- query: threadId ? makeURLSearchParams({ thread_id: threadId }) : undefined,
- auth: false,
- });
+ const data = await this.client.rest.get(
+ Routes.webhookMessage(this.id, this.token, message),
+ {
+ query: threadId
+ ? makeURLSearchParams({ thread_id: threadId })
+ : undefined,
+ auth: false,
+ }
+ );
if (!this.client.channels) return data;
return (
- this.client.channels.cache.get(data.channel_id)?.messages._add(data, false) ??
- new (getMessage())(this.client, data)
+ this.client.channels.cache
+ .get(data.channel_id)
+ ?.messages._add(data, false) ?? new (getMessage())(this.client, data)
);
}
@@ -315,7 +345,8 @@ class Webhook {
* @returns {Promise} Returns the message edited by this webhook
*/
async editMessage(message, options) {
- if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
+ if (!this.token)
+ throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
let messagePayload;
@@ -325,7 +356,11 @@ class Webhook {
const { body, files } = await messagePayload.resolveBody().resolveFiles();
const d = await this.client.rest.patch(
- Routes.webhookMessage(this.id, this.token, typeof message === 'string' ? message : message.id),
+ Routes.webhookMessage(
+ this.id,
+ this.token,
+ typeof message === "string" ? message : message.id
+ ),
{
body,
files,
@@ -333,7 +368,7 @@ class Webhook {
? makeURLSearchParams({ thread_id: messagePayload.options.threadId })
: undefined,
auth: false,
- },
+ }
);
const channelManager = this.client.channels;
@@ -356,7 +391,10 @@ class Webhook {
* @returns {Promise}
*/
async delete(reason) {
- await this.client.rest.delete(Routes.webhook(this.id, this.token), { reason, auth: !this.token });
+ await this.client.rest.delete(Routes.webhook(this.id, this.token), {
+ reason,
+ auth: !this.token,
+ });
}
/**
@@ -366,14 +404,21 @@ class Webhook {
* @returns {Promise}
*/
async deleteMessage(message, threadId) {
- if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
+ if (!this.token)
+ throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
await this.client.rest.delete(
- Routes.webhookMessage(this.id, this.token, typeof message === 'string' ? message : message.id),
+ Routes.webhookMessage(
+ this.id,
+ this.token,
+ typeof message === "string" ? message : message.id
+ ),
{
- query: threadId ? makeURLSearchParams({ thread_id: threadId }) : undefined,
+ query: threadId
+ ? makeURLSearchParams({ thread_id: threadId })
+ : undefined,
auth: false,
- },
+ }
);
}
@@ -410,7 +455,9 @@ class Webhook {
* @returns {?string}
*/
avatarURL(options = {}) {
- return this.avatar && this.client.rest.cdn.avatar(this.id, this.avatar, options);
+ return (
+ this.avatar && this.client.rest.cdn.avatar(this.id, this.avatar, options)
+ );
}
/**
@@ -418,7 +465,9 @@ class Webhook {
* @returns {boolean}
*/
isUserCreated() {
- return Boolean(this.type === WebhookType.Incoming && this.owner && !this.owner.bot);
+ return Boolean(
+ this.type === WebhookType.Incoming && this.owner && !this.owner.bot
+ );
}
/**
@@ -447,19 +496,23 @@ class Webhook {
static applyToClass(structure, ignore = []) {
for (const prop of [
- 'send',
- 'sendSlackMessage',
- 'fetchMessage',
- 'edit',
- 'editMessage',
- 'delete',
- 'deleteMessage',
- 'createdTimestamp',
- 'createdAt',
- 'url',
+ "send",
+ "sendSlackMessage",
+ "fetchMessage",
+ "edit",
+ "editMessage",
+ "delete",
+ "deleteMessage",
+ "createdTimestamp",
+ "createdAt",
+ "url",
]) {
if (ignore.includes(prop)) continue;
- Object.defineProperty(structure.prototype, prop, Object.getOwnPropertyDescriptor(Webhook.prototype, prop));
+ Object.defineProperty(
+ structure.prototype,
+ prop,
+ Object.getOwnPropertyDescriptor(Webhook.prototype, prop)
+ );
}
}
}
diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts
index f0f94e8dcffc..5b3ff4889c69 100644
--- a/packages/discord.js/typings/index.d.ts
+++ b/packages/discord.js/typings/index.d.ts
@@ -2908,7 +2908,7 @@ export class Webhook extends WebhookMixin() {
public token: string | null;
public type: WebhookType;
public applicationId: Snowflake | null;
- public get channel(): GuildTextBasedChannel | ForumChannel | null;
+ public get channel(): TextChannel | VoiceChannel | NewsChannel | ForumChannel | null;
public isUserCreated(): this is this & {
type: WebhookType.Incoming;
applicationId: null;
From 97be09dace8332e8affaae70e2f2cd34c7a99161 Mon Sep 17 00:00:00 2001
From: MrMythical <91077061+MrMythicalYT@users.noreply.github.com>
Date: Sat, 5 Nov 2022 23:41:54 -0400
Subject: [PATCH 4/5] fix: formatting
---
packages/discord.js/src/structures/Webhook.js | 169 +++++++-----------
1 file changed, 64 insertions(+), 105 deletions(-)
diff --git a/packages/discord.js/src/structures/Webhook.js b/packages/discord.js/src/structures/Webhook.js
index ef2a19e350cb..2e275bde3c12 100644
--- a/packages/discord.js/src/structures/Webhook.js
+++ b/packages/discord.js/src/structures/Webhook.js
@@ -1,14 +1,14 @@
-"use strict";
+'use strict';
-const { makeURLSearchParams } = require("@discordjs/rest");
-const { lazy } = require("@discordjs/util");
-const { DiscordSnowflake } = require("@sapphire/snowflake");
-const { Routes, WebhookType } = require("discord-api-types/v10");
-const MessagePayload = require("./MessagePayload");
-const { DiscordjsError, ErrorCodes } = require("../errors");
-const DataResolver = require("../util/DataResolver");
+const { makeURLSearchParams } = require('@discordjs/rest');
+const { lazy } = require('@discordjs/util');
+const { DiscordSnowflake } = require('@sapphire/snowflake');
+const { Routes, WebhookType } = require('discord-api-types/v10');
+const MessagePayload = require('./MessagePayload');
+const { DiscordjsError, ErrorCodes } = require('../errors');
+const DataResolver = require('../util/DataResolver');
-const getMessage = lazy(() => require("./Message").Message);
+const getMessage = lazy(() => require('./Message').Message);
/**
* Represents a webhook.
@@ -21,12 +21,12 @@ class Webhook {
* @type {Client}
* @readonly
*/
- Object.defineProperty(this, "client", { value: client });
+ Object.defineProperty(this, 'client', { value: client });
if (data) this._patch(data);
}
_patch(data) {
- if ("name" in data) {
+ if ('name' in data) {
/**
* The name of the webhook
* @type {string}
@@ -39,13 +39,13 @@ class Webhook {
* @name Webhook#token
* @type {?string}
*/
- Object.defineProperty(this, "token", {
+ Object.defineProperty(this, 'token', {
value: data.token ?? null,
writable: true,
configurable: true,
});
- if ("avatar" in data) {
+ if ('avatar' in data) {
/**
* The avatar for the webhook
* @type {?string}
@@ -59,7 +59,7 @@ class Webhook {
*/
this.id = data.id;
- if ("type" in data) {
+ if ('type' in data) {
/**
* The type of the webhook
* @type {WebhookType}
@@ -67,7 +67,7 @@ class Webhook {
this.type = data.type;
}
- if ("guild_id" in data) {
+ if ('guild_id' in data) {
/**
* The guild the webhook belongs to
* @type {Snowflake}
@@ -75,7 +75,7 @@ class Webhook {
this.guildId = data.guild_id;
}
- if ("channel_id" in data) {
+ if ('channel_id' in data) {
/**
* The id of the channel the webhook belongs to
* @type {Snowflake}
@@ -83,7 +83,7 @@ class Webhook {
this.channelId = data.channel_id;
}
- if ("user" in data) {
+ if ('user' in data) {
/**
* The owner of the webhook
* @type {?(User|APIUser)}
@@ -93,7 +93,7 @@ class Webhook {
this.owner ??= null;
}
- if ("application_id" in data) {
+ if ('application_id' in data) {
/**
* The application that created this webhook
* @type {?Snowflake}
@@ -103,25 +103,22 @@ class Webhook {
this.applicationId ??= null;
}
- if ("source_guild" in data) {
+ if ('source_guild' in data) {
/**
* The source guild of the webhook
* @type {?(Guild|APIGuild)}
*/
- this.sourceGuild =
- this.client.guilds?.resolve(data.source_guild.id) ?? data.source_guild;
+ this.sourceGuild = this.client.guilds?.resolve(data.source_guild.id) ?? data.source_guild;
} else {
this.sourceGuild ??= null;
}
- if ("source_channel" in data) {
+ if ('source_channel' in data) {
/**
* The source channel of the webhook
* @type {?(NewsChannel|APIChannel)}
*/
- this.sourceChannel =
- this.client.channels?.resolve(data.source_channel?.id) ??
- data.source_channel;
+ this.sourceChannel = this.client.channels?.resolve(data.source_channel?.id) ?? data.source_channel;
} else {
this.sourceChannel ??= null;
}
@@ -204,8 +201,7 @@ class Webhook {
* .catch(console.error);
*/
async send(options) {
- if (!this.token)
- throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
+ if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
let messagePayload;
@@ -229,10 +225,7 @@ class Webhook {
});
if (!this.client.channels) return d;
- return (
- this.client.channels.cache.get(d.channel_id)?.messages._add(d, false) ??
- new (getMessage())(this.client, d)
- );
+ return this.client.channels.cache.get(d.channel_id)?.messages._add(d, false) ?? new (getMessage())(this.client, d);
}
/**
@@ -254,18 +247,14 @@ class Webhook {
* @see {@link https://api.slack.com/messaging/webhooks}
*/
async sendSlackMessage(body) {
- if (!this.token)
- throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
+ if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
- const data = await this.client.rest.post(
- Routes.webhookPlatform(this.id, this.token, "slack"),
- {
- query: makeURLSearchParams({ wait: true }),
- auth: false,
- body,
- }
- );
- return data.toString() === "ok";
+ const data = await this.client.rest.post(Routes.webhookPlatform(this.id, this.token, 'slack'), {
+ query: makeURLSearchParams({ wait: true }),
+ auth: false,
+ body,
+ });
+ return data.toString() === 'ok';
}
/**
@@ -283,18 +272,15 @@ class Webhook {
* @returns {Promise}
*/
async edit({ name = this.name, avatar, channel, reason }) {
- if (avatar && !(typeof avatar === "string" && avatar.startsWith("data:"))) {
+ if (avatar && !(typeof avatar === 'string' && avatar.startsWith('data:'))) {
avatar = await DataResolver.resolveImage(avatar);
}
channel &&= channel.id ?? channel;
- const data = await this.client.rest.patch(
- Routes.webhook(this.id, channel ? undefined : this.token),
- {
- body: { name, avatar, channel_id: channel },
- reason,
- auth: !this.token || Boolean(channel),
- }
- );
+ const data = await this.client.rest.patch(Routes.webhook(this.id, channel ? undefined : this.token), {
+ body: { name, avatar, channel_id: channel },
+ reason,
+ auth: !this.token || Boolean(channel),
+ });
this.name = data.name;
this.avatar = data.avatar;
@@ -317,24 +303,17 @@ class Webhook {
* @returns {Promise} Returns the message sent by this webhook
*/
async fetchMessage(message, { threadId } = {}) {
- if (!this.token)
- throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
+ if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
- const data = await this.client.rest.get(
- Routes.webhookMessage(this.id, this.token, message),
- {
- query: threadId
- ? makeURLSearchParams({ thread_id: threadId })
- : undefined,
- auth: false,
- }
- );
+ const data = await this.client.rest.get(Routes.webhookMessage(this.id, this.token, message), {
+ query: threadId ? makeURLSearchParams({ thread_id: threadId }) : undefined,
+ auth: false,
+ });
if (!this.client.channels) return data;
return (
- this.client.channels.cache
- .get(data.channel_id)
- ?.messages._add(data, false) ?? new (getMessage())(this.client, data)
+ this.client.channels.cache.get(data.channel_id)?.messages._add(data, false) ??
+ new (getMessage())(this.client, data)
);
}
@@ -345,8 +324,7 @@ class Webhook {
* @returns {Promise} Returns the message edited by this webhook
*/
async editMessage(message, options) {
- if (!this.token)
- throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
+ if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
let messagePayload;
@@ -356,11 +334,7 @@ class Webhook {
const { body, files } = await messagePayload.resolveBody().resolveFiles();
const d = await this.client.rest.patch(
- Routes.webhookMessage(
- this.id,
- this.token,
- typeof message === "string" ? message : message.id
- ),
+ Routes.webhookMessage(this.id, this.token, typeof message === 'string' ? message : message.id),
{
body,
files,
@@ -368,7 +342,7 @@ class Webhook {
? makeURLSearchParams({ thread_id: messagePayload.options.threadId })
: undefined,
auth: false,
- }
+ },
);
const channelManager = this.client.channels;
@@ -404,21 +378,14 @@ class Webhook {
* @returns {Promise}
*/
async deleteMessage(message, threadId) {
- if (!this.token)
- throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
+ if (!this.token) throw new DiscordjsError(ErrorCodes.WebhookTokenUnavailable);
await this.client.rest.delete(
- Routes.webhookMessage(
- this.id,
- this.token,
- typeof message === "string" ? message : message.id
- ),
+ Routes.webhookMessage(this.id, this.token, typeof message === 'string' ? message : message.id),
{
- query: threadId
- ? makeURLSearchParams({ thread_id: threadId })
- : undefined,
+ query: threadId ? makeURLSearchParams({ thread_id: threadId }) : undefined,
auth: false,
- }
+ },
);
}
@@ -455,9 +422,7 @@ class Webhook {
* @returns {?string}
*/
avatarURL(options = {}) {
- return (
- this.avatar && this.client.rest.cdn.avatar(this.id, this.avatar, options)
- );
+ return this.avatar && this.client.rest.cdn.avatar(this.id, this.avatar, options);
}
/**
@@ -465,9 +430,7 @@ class Webhook {
* @returns {boolean}
*/
isUserCreated() {
- return Boolean(
- this.type === WebhookType.Incoming && this.owner && !this.owner.bot
- );
+ return Boolean(this.type === WebhookType.Incoming && this.owner && !this.owner.bot);
}
/**
@@ -496,23 +459,19 @@ class Webhook {
static applyToClass(structure, ignore = []) {
for (const prop of [
- "send",
- "sendSlackMessage",
- "fetchMessage",
- "edit",
- "editMessage",
- "delete",
- "deleteMessage",
- "createdTimestamp",
- "createdAt",
- "url",
+ 'send',
+ 'sendSlackMessage',
+ 'fetchMessage',
+ 'edit',
+ 'editMessage',
+ 'delete',
+ 'deleteMessage',
+ 'createdTimestamp',
+ 'createdAt',
+ 'url',
]) {
if (ignore.includes(prop)) continue;
- Object.defineProperty(
- structure.prototype,
- prop,
- Object.getOwnPropertyDescriptor(Webhook.prototype, prop)
- );
+ Object.defineProperty(structure.prototype, prop, Object.getOwnPropertyDescriptor(Webhook.prototype, prop));
}
}
}
From ccb21bb4619bedc7cca802f8ca4da89a1e44dc4a Mon Sep 17 00:00:00 2001
From: MrMythicalYT <91077061+MrMythicalYT@users.noreply.github.com>
Date: Sat, 19 Nov 2022 20:09:28 -0400
Subject: [PATCH 5/5] Apply suggestions from code review
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Aura Román
---
packages/discord.js/src/structures/Webhook.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/packages/discord.js/src/structures/Webhook.js b/packages/discord.js/src/structures/Webhook.js
index 2e275bde3c12..4ac020a41872 100644
--- a/packages/discord.js/src/structures/Webhook.js
+++ b/packages/discord.js/src/structures/Webhook.js
@@ -144,14 +144,16 @@ class Webhook {
* @property {Snowflake} [threadId] The id of the thread this message belongs to
* For interaction webhooks, this property is ignored
*/
+
/**
- * The channel that this webhook belongs to
+ * The channel the webhook belongs to
* @type {?(TextChannel|VoiceChannel|NewsChannel|ForumChannel)}
* @readonly
*/
get channel() {
return this.client.channels.resolve(this.channelId);
}
+
/**
* Sends a message with this webhook.
* @param {string|MessagePayload|WebhookCreateMessageOptions} options The options to provide