Skip to content

fix(ChannelUpdateAction): emit client event in handle to not miss change #10690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/discord.js/src/client/actions/ChannelUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const Action = require('./Action');
const { createChannel } = require('../../util/Channels');
const Events = require('../../util/Events');

class ChannelUpdateAction extends Action {
handle(data) {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
};
Original file line number Diff line number Diff line change
@@ -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);
};
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/ThreadChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading