diff --git a/packages/discord.js/src/client/actions/ChannelUpdate.js b/packages/discord.js/src/client/actions/ChannelUpdate.js index 7ca331aacae9..ac32e0ae9a97 100644 --- a/packages/discord.js/src/client/actions/ChannelUpdate.js +++ b/packages/discord.js/src/client/actions/ChannelUpdate.js @@ -2,6 +2,7 @@ const Action = require('./Action'); const { createChannel } = require('../../util/Channels'); +const Events = require('../../util/Events'); class ChannelUpdateAction extends Action { handle(data) { @@ -27,6 +28,24 @@ class ChannelUpdateAction extends Action { this.client.channels.cache.set(channel.id, channel); } + if (channel.isThread()) { + /** + * Emitted whenever a thread is updated - e.g. name change, archive state change, locked state change. + * @event Client#threadUpdate + * @param {ThreadChannel} oldThread The thread before the update + * @param {ThreadChannel} newThread The thread after the update + */ + client.emit(Events.ThreadUpdate, old, channel); + } else { + /** + * Emitted whenever a channel is updated - e.g. name change, topic change, channel type change. + * @event Client#channelUpdate + * @param {DMChannel|GuildChannel} oldChannel The channel before the update + * @param {DMChannel|GuildChannel} newChannel The channel after the update + */ + client.emit(Events.ChannelUpdate, old, channel); + } + return { old, updated: channel, diff --git a/packages/discord.js/src/client/websocket/handlers/CHANNEL_UPDATE.js b/packages/discord.js/src/client/websocket/handlers/CHANNEL_UPDATE.js index 8f35121b0a7d..94d463a7a601 100644 --- a/packages/discord.js/src/client/websocket/handlers/CHANNEL_UPDATE.js +++ b/packages/discord.js/src/client/websocket/handlers/CHANNEL_UPDATE.js @@ -1,16 +1,5 @@ 'use strict'; -const Events = require('../../../util/Events'); - module.exports = (client, packet) => { - const { old, updated } = client.actions.ChannelUpdate.handle(packet.d); - if (old && updated) { - /** - * Emitted whenever a channel is updated - e.g. name change, topic change, channel type change. - * @event Client#channelUpdate - * @param {DMChannel|GuildChannel} oldChannel The channel before the update - * @param {DMChannel|GuildChannel} newChannel The channel after the update - */ - client.emit(Events.ChannelUpdate, old, updated); - } + client.actions.ChannelUpdate.handle(packet.d); }; diff --git a/packages/discord.js/src/client/websocket/handlers/THREAD_UPDATE.js b/packages/discord.js/src/client/websocket/handlers/THREAD_UPDATE.js index 481dcd476365..94d463a7a601 100644 --- a/packages/discord.js/src/client/websocket/handlers/THREAD_UPDATE.js +++ b/packages/discord.js/src/client/websocket/handlers/THREAD_UPDATE.js @@ -1,16 +1,5 @@ 'use strict'; -const Events = require('../../../util/Events'); - module.exports = (client, packet) => { - const { old, updated } = client.actions.ChannelUpdate.handle(packet.d); - if (old && updated) { - /** - * Emitted whenever a thread is updated - e.g. name change, archive state change, locked state change. - * @event Client#threadUpdate - * @param {ThreadChannel} oldThread The thread before the update - * @param {ThreadChannel} newThread The thread after the update - */ - client.emit(Events.ThreadUpdate, old, updated); - } + client.actions.ChannelUpdate.handle(packet.d); }; diff --git a/packages/discord.js/src/structures/ThreadChannel.js b/packages/discord.js/src/structures/ThreadChannel.js index 1fa63b2ccd10..f4ef575b7749 100644 --- a/packages/discord.js/src/structures/ThreadChannel.js +++ b/packages/discord.js/src/structures/ThreadChannel.js @@ -343,7 +343,7 @@ class ThreadChannel extends BaseChannel { async edit(options) { const newData = await this.client.rest.patch(Routes.channel(this.id), { body: { - name: (options.name ?? this.name).trim(), + name: options.name, archived: options.archived, auto_archive_duration: options.autoArchiveDuration, rate_limit_per_user: options.rateLimitPerUser,