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 12 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 @@ -281,6 +281,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 @@ -2283,6 +2289,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, channelPositions: ChannelPosition[], reason?: string): 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 {
dynamicIconURL(format?: ImageFormat, size?: number): string | null;
dynamicSplashURL(format?: ImageFormat, size?: number): string | null;
edit(options: GuildOptions, reason?: string): Promise<Guild>;
editChannelPositions(channelPositions: ChannelPosition[], reason?: string): Promise<void>;
editCommand(commandID: string, command: ApplicationCommandStructure): Promise<ApplicationCommand>;
editCommandPermissions(permissions: ApplicationCommandPermissions[]): Promise<GuildApplicationCommandPermissions[]>;
editDiscovery(options?: DiscoveryOptions): Promise<DiscoveryMetadata>;
Expand Down
24 changes: 24 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,30 @@ class Client extends EventEmitter {
}).then((guild) => new Guild(guild, this));
}

/**
* Edit guild channel 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>} 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 permissions with the new parent if moving to a new category
* @arg {String} [channelPositions[].parentID] The new parent ID (category channel) for the channel that is moved (only one channel can change category per request)
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise}
*/
editGuildChannelPositions(guildID, channelPositions, reason) {
const body = channelPositions.map((channelPosition) => {
return {
id: channelPosition.id,
position: channelPosition.position,
lock_permissions: channelPosition.lockPermissions,
parent_id: channelPosition.parentID
};
});
body.reason = reason;
return this.requestHandler.request("PATCH", Endpoints.GUILD_CHANNELS(guildID), true, body);
}

/**
* Edit a guild application command
* @arg {String} guildID The guild id
Expand Down
14 changes: 14 additions & 0 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,20 @@ 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>} 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 permissions with the new parent if moving to a new category
* @arg {String} [channelPositions[].parentID] The new parent ID (category channel) for the channel that is moved (only one channel can change category per request)
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise}
*/
editChannelPositions(channelPositions, reason) {
return this._client.editGuildChannelPositions.call(this._client, this.id, channelPositions, reason);
}

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