refactor: move Guild setPositions methods to managers (#6875)

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
Rodry
2021-10-26 20:28:56 +01:00
committed by GitHub
parent b27888455f
commit e12a5b6a0c
4 changed files with 61 additions and 28 deletions

View File

@@ -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