fix: return types [] => Collection

This commit is contained in:
Skillz4Killz
2021-04-13 17:53:49 +00:00
committed by GitHub
parent f8d6a74948
commit c2f2afb211
8 changed files with 91 additions and 34 deletions
+12 -2
View File
@@ -1,6 +1,9 @@
import { rest } from "../../rest/rest.ts";
import { DiscordRole, Role } from "../../types/permissions/role.ts";
import { Collection } from "../../util/collection.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { snakeKeysToCamelCase } from "../../util/utils.ts";
/** Returns a list of role objects for the guild.
*
@@ -9,7 +12,14 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
export async function getRoles(guildId: string) {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
const result = await rest.runMethod("get", endpoints.GUILD_ROLES(guildId));
const result = (await rest.runMethod(
"get",
endpoints.GUILD_ROLES(guildId)
)) as DiscordRole[];
return result;
return new Collection(
result
.map((role) => snakeKeysToCamelCase<Role>(role))
.map((role) => [role.id, role])
);
}