mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor: move Guild setPositions methods to managers (#6875)
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
@@ -192,6 +192,31 @@ class GuildChannelManager extends CachedManager {
|
||||
return channels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Batch-updates the guild's channels' positions.
|
||||
* <info>Only one channel's parent can be changed at a time</info>
|
||||
* @param {ChannelPosition[]} channelPositions Channel positions to update
|
||||
* @returns {Promise<Guild>}
|
||||
* @example
|
||||
* guild.channels.setPositions([{ channel: channelId, position: newChannelIndex }])
|
||||
* .then(guild => console.log(`Updated channel positions for ${guild}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async setPositions(channelPositions) {
|
||||
channelPositions = channelPositions.map(r => ({
|
||||
id: this.client.channels.resolveId(r.channel),
|
||||
position: r.position,
|
||||
lock_permissions: r.lockPermissions,
|
||||
parent_id: typeof r.parent !== 'undefined' ? this.channels.resolveId(r.parent) : undefined,
|
||||
}));
|
||||
|
||||
await this.client.api.guilds(this.id).channels.patch({ data: channelPositions });
|
||||
return this.client.actions.GuildChannelsPositionUpdate.handle({
|
||||
guild_id: this.id,
|
||||
channels: channelPositions,
|
||||
}).guild;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains all active thread channels in the guild from Discord
|
||||
* @param {boolean} [cache=true] Whether to cache the fetched data
|
||||
|
||||
Reference in New Issue
Block a user