mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
fix: add modifyRolePositions
This commit is contained in:
@@ -3,4 +3,5 @@ export * from "./createRole.ts";
|
||||
export * from "./deleteRole.ts";
|
||||
export * from "./editRole.ts";
|
||||
export * from "./getRoles.ts";
|
||||
export * from "./modifyRolePositions.ts";
|
||||
export * from "./removeRole.ts";
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Bot } from "../../bot.ts";
|
||||
import { DiscordRole } from "../../types/discord.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
|
||||
/** Modify the positions of a set of role objects for the guild. Requires the MANAGE_ROLES permission. Returns a list of all of the guild's role objects on success. Fires multiple Guild Role Update Gateway events. */
|
||||
export async function modifyRolePositions(bot: Bot, guildId: bigint, options: ModifyRolePositions[]) {
|
||||
const roles = await bot.rest.runMethod<DiscordRole[]>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.GUILD_ROLES(guildId),
|
||||
options,
|
||||
);
|
||||
|
||||
return new Collection(roles.map((role) => {
|
||||
const result = bot.transformers.role(bot, { role, guildId });
|
||||
return [result.id, result];
|
||||
}));
|
||||
}
|
||||
|
||||
export interface ModifyRolePositions {
|
||||
/** The role id */
|
||||
id: bigint;
|
||||
/** The sorting position for the role. */
|
||||
position?: number | null;
|
||||
}
|
||||
|
||||
@@ -29,3 +29,4 @@ export default function editRole(bot: BotWithCache) {
|
||||
return await editRoleOld(guildId, id, options);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { BotWithCache } from "../../deps.ts";
|
||||
import { requireBotGuildPermissions } from "../permissions.ts";
|
||||
|
||||
export function modifyRolePositions(bot: BotWithCache) {
|
||||
const modifyRolePositionsOld = bot.helpers.modifyRolePositions;
|
||||
|
||||
bot.helpers.modifyRolePositions = async function (guildId, categoryId) {
|
||||
requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]);
|
||||
|
||||
return await modifyRolePositionsOld(guildId, categoryId);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user