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 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
8 changes: 8 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ declare namespace Eris {
channel_id: string;
webhook_id: string;
}
interface ChannelPosition {
id: string;
position: number;
lockPermissions?: boolean;
parentID?: string;
}
interface CreateChannelOptions {
bitrate?: number;
nsfw?: boolean;
Expand Down Expand Up @@ -2288,6 +2294,7 @@ declare namespace Eris {
reason?: string
): Promise<void>;
editChannelPosition(channelID: string, position: number, options?: EditChannelPositionOptions): Promise<void>;
editChannelPositions(guildID: string, channelPositions: ChannelPosition[]): Promise<void>;
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>;
Expand Down Expand Up @@ -2721,6 +2728,7 @@ declare namespace Eris {
dynamicIconURL(format?: ImageFormat, size?: number): string | null;
dynamicSplashURL(format?: ImageFormat, size?: number): string | null;
edit(options: GuildOptions, reason?: string): Promise<Guild>;
editChannelPositions(channelPositions: ChannelPosition[]): Promise<void>;
editCommand(commandID: string, command: ApplicationCommandStructure): Promise<ApplicationCommand>;
editCommandPermissions(permissions: ApplicationCommandPermissions[]): Promise<GuildApplicationCommandPermissions[]>;
editDiscovery(options?: DiscoveryOptions): Promise<DiscoveryMetadata>;
Expand Down
25 changes: 23 additions & 2 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1296,11 +1296,11 @@ class Client extends EventEmitter {
}

/**
* Edit a guild channel's position. Note that channel position numbers are lowest on top and highest at the bottom.
* Edit a guild channel's position. Note that channel position numbers are grouped by type (category, text, voice), then sorted in ascending order (lowest number is on top).
* @arg {String} channelID The ID of the channel
* @arg {Number} position The new position of the channel
* @arg {Object} [options] Additional options when editing position
* @arg {Boolean} [options.lockPermissions] Whether to sync the permissions with the new parent if moving to a new category
* @arg {Boolean} [options.lockPermissions] Whether to sync the channel's permissions with the new parent, if changing parents
* @arg {String} [options.parentID] The new parent ID (category channel) for the channel that is moved
* @returns {Promise}
*/
Expand Down Expand Up @@ -1334,6 +1334,27 @@ class Client extends EventEmitter {
})));
}

/**
* Edit multiple guild channels' positions. Note that channel position numbers are grouped by type (category, text, voice), then sorted in ascending order (lowest number is on top).
* @arg {String} guildID The ID of the guild
* @arg {Array<Object>} channelPositions An array of [ChannelPosition](https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions)
* @arg {String} channelPositions[].id The ID of the channel
* @arg {Number} channelPositions[].position The new position of the channel
* @arg {Boolean} [channelPositions[].lockPermissions] Whether to sync the channel's permissions with the new parent, if changing parents
* @arg {String} [channelPositions[].parentID] The new parent ID (category channel) for the channel that is moved. For each request, only one channel can change parents
* @returns {Promise}
*/
editChannelPositions(guildID, channelPositions) {
return this.requestHandler.request("PATCH", Endpoints.GUILD_CHANNELS(guildID), true, channelPositions.map((channelPosition) => {
return {
id: channelPosition.id,
position: channelPosition.position,
lock_permissions: channelPosition.lockPermissions,
parent_id: channelPosition.parentID
};
}));
}

/**
* Edit a global application command
* @arg {String} commandID The command 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 @@ -617,6 +617,19 @@ class Guild extends Base {
return this._client.editGuild.call(this._client, this.id, options, reason);
}

/**
* Edit multiple channels' positions. Note that channel position numbers are grouped by type (category, text, voice), then sorted in ascending order (lowest number is on top).
* @arg {Array<Object>} channelPositions An array of [ChannelPosition](https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions)
* @arg {String} channelPositions[].id The ID of the channel
* @arg {Number} channelPositions[].position The new position of the channel
* @arg {Boolean} [channelPositions[].lockPermissions] Whether to sync the channel's permissions with the new parent, if changing parents
* @arg {String} [channelPositions[].parentID] The new parent ID (category channel) for the channel that is moved. For each request, only one channel can change parents
* @returns {Promise}
*/
editChannelPositions(channelPositions) {
return this._client.editChannelPositions.call(this._client, this.id, channelPositions);
}

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