mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
handlers
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
import { eventHandlers } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { Bot } from "../../bot.ts";
|
||||
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
|
||||
import type { GuildRoleDelete } from "../../types/guilds/guild_role_delete.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
|
||||
|
||||
export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
|
||||
const payload = data.d as GuildRoleDelete;
|
||||
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
|
||||
export async function handleGuildRoleDelete(bot: Bot, data: DiscordGatewayPayload) {
|
||||
const payload = data.d as SnakeCasedPropertiesDeep<GuildRoleDelete>;
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id);
|
||||
const guild = await bot.cache.guilds.get(guildId);
|
||||
if (!guild) return;
|
||||
|
||||
const roleId = snowflakeToBigint(payload.roleId);
|
||||
const roleId = bot.transformers.snowflake(payload.role_id);
|
||||
|
||||
const cachedRole = guild.roles.get(roleId)!;
|
||||
const cachedRole = guild.roles.get(roleId);
|
||||
guild.roles.delete(roleId);
|
||||
|
||||
if (cachedRole) eventHandlers.roleDelete?.(guild, cachedRole);
|
||||
await bot.cache.guilds.set(guild.id, guild);
|
||||
|
||||
if (cachedRole) bot.events.roleDelete(bot, guild, cachedRole);
|
||||
|
||||
// For bots without GUILD_MEMBERS member.roles is never updated breaking permissions checking.
|
||||
await cacheHandlers.forEach("DELETE_ROLE_FROM_MEMBER", { guildId: guild.id, roleId });
|
||||
await bot.cache.execute("DELETE_ROLE_FROM_MEMBER", { guildId: guild.id, roleId });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user