Skip to content
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

feat(editChannelPositions): add support for endpoint #1328

Merged
merged 18 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,12 @@ declare namespace Eris {
}

// Guild
interface GuildChannelPosition {
id: string;
position: number;
lockPermissions?: boolean;
parentID?: string;
}
carloslimaborges marked this conversation as resolved.
Show resolved Hide resolved
interface CreateGuildOptions {
afkChannelID?: string;
afkTimeout?: number;
Expand Down Expand Up @@ -2282,6 +2288,7 @@ declare namespace Eris {
editCommand(commandID: string, command: ApplicationCommandStructure): Promise<ApplicationCommand>;
editCommandPermissions(guildID: string, commandID: string, permissions: ApplicationCommandPermissions[]): Promise<GuildApplicationCommandPermissions>;
editGuild(guildID: string, options: GuildOptions, reason?: string): Promise<Guild>;
editGuildChannelPositions(guildID: string, guildChannelPositions: GuildChannelPosition[]): Promise<void>;
editGuildCommand(guildID: string, commandID: string, command: ApplicationCommandStructure): Promise<ApplicationCommand>;
editGuildDiscovery(guildID: string, options?: DiscoveryOptions): Promise<DiscoveryMetadata>;
editGuildEmoji(
Expand Down Expand Up @@ -2711,6 +2718,7 @@ declare namespace Eris {
dynamicSplashURL(format?: ImageFormat, size?: number): string | null;
edit(options: GuildOptions, reason?: string): Promise<Guild>;
editCommand(commandID: string, command: ApplicationCommandStructure): Promise<ApplicationCommand>;
editChannelPositions(guildChannelPositions: GuildChannelPosition[]): Promise<void>;
editCommandPermissions(permissions: ApplicationCommandPermissions[]): Promise<GuildApplicationCommandPermissions[]>;
editDiscovery(options?: DiscoveryOptions): Promise<DiscoveryMetadata>;
editEmoji(emojiID: string, options: { name: string; roles?: string[] }, reason?: string): Promise<Emoji>;
Expand Down
24 changes: 24 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,30 @@ class Client extends EventEmitter {
}).then((guild) => new Guild(guild, this));
}

/**
* Edit guild channels' positions. Note that channel position numbers are lowest on top and highest at the bottom.
carloslimaborges marked this conversation as resolved.
Show resolved Hide resolved
* @arg {String} guildID The ID of the guild
* @arg {Array<Object>} guildChannelPositions An array of [GuildChannelPosition] (https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions)
* @arg {String} GuildChannelPosition[].id The ID of the channel
* @arg {Number} GuildChannelPosition[].position The new position of the channel
* @arg {Boolean} [GuildChannelPosition[].lockPermissions] Whether to sync the permissions with the new parent if moving to a new category
* @arg {String} [GuildChannelPosition[].parentID] The new parent ID (category channel) for the channel that is moved (only one channel can change category per request)
* @returns {Promise}
*/
editGuildChannelPositions(guildID, guildChannelPositions) {
const guild = this.guilds.get(guildID);
if(!guild) {
return Promise.reject(new Error(`Guild ${guildID} not found`));
}
guildChannelPositions.forEach((channelPosition) => {
const channel = guild.channels.get(channelPosition.id);
if(!channel) {
return Promise.reject(new Error(`Channel ${channelPosition.id} not found`));
}
});
carloslimaborges marked this conversation as resolved.
Show resolved Hide resolved
return this.requestHandler.request("PATCH", Endpoints.GUILD_CHANNELS(guildID), true, guildChannelPositions);
carloslimaborges marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Edit a guild application command
* @arg {String} guildID The guild id
Expand Down
13 changes: 13 additions & 0 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,19 @@ class Guild extends Base {
return this._client.editGuild.call(this._client, this.id, options, reason);
}

/**
* Edit guild channels' positions. Note that channel position numbers are lowest on top and highest at the bottom.
* @arg {Array<Object>} guildChannelPositions An array of [GuildChannelPosition] (https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions)
* @arg {String} GuildChannelPosition[].id The ID of the channel
* @arg {Number} GuildChannelPosition[].position The new position of the channel
* @arg {Boolean} [GuildChannelPosition[].lockPermissions] Whether to sync the permissions with the new parent if moving to a new category
* @arg {String} [GuildChannelPosition[].parentID] The new parent ID (category channel) for the channel that is moved (only one channel can change category per request)
* @returns {Promise}
*/
editChannelPositions(guildChannelPositions) {
return this._client.editGuildChannelPositions.call(this._client, this.id, guildChannelPositions);
}

/**
* Edit a guild application command
* @arg {String} commandID The command id
Expand Down