From 1db6aaac8d88e027b267182f76c9d8dce2e43895 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Sat, 28 Nov 2020 10:51:49 +0530 Subject: [PATCH] fix: errors --- src/gateway/handlers/guildMemberUpdate.ts | 3 +- src/gateway/handlers/guildRoleCreate.ts | 31 ++++++++--------- src/gateway/handlers/guildRoleUpdate.ts | 41 ++++++++++++----------- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/gateway/handlers/guildMemberUpdate.ts b/src/gateway/handlers/guildMemberUpdate.ts index 6d06a45..38c7f1b 100644 --- a/src/gateway/handlers/guildMemberUpdate.ts +++ b/src/gateway/handlers/guildMemberUpdate.ts @@ -2,6 +2,7 @@ import { Gateway, GatewayEventHandler } from '../index.ts' import { Guild } from '../../structures/guild.ts' import { GuildMemberUpdatePayload } from '../../types/gateway.ts' import { MemberPayload } from '../../types/guild.ts' +import { Member } from "../../structures/member.ts" export const guildMemberUpdate: GatewayEventHandler = async ( gateway: Gateway, @@ -25,7 +26,7 @@ export const guildMemberUpdate: GatewayEventHandler = async ( const newMember = await guild.members.get(d.user.id) if (member !== undefined) - gateway.client.emit('guildMemberRemove', member, newMember) + gateway.client.emit('guildMemberUpdate', member, (newMember as unknown) as Member) else { gateway.client.emit('guildMemberUpdateUncached', newMember) } diff --git a/src/gateway/handlers/guildRoleCreate.ts b/src/gateway/handlers/guildRoleCreate.ts index 90f91c1..c1470a8 100644 --- a/src/gateway/handlers/guildRoleCreate.ts +++ b/src/gateway/handlers/guildRoleCreate.ts @@ -1,16 +1,17 @@ -import { Gateway, GatewayEventHandler } from '../index.ts' -import { Guild } from '../../structures/guild.ts' -import { GuildRoleCreatePayload } from "../../types/gateway.ts" - -export const guildRoleCreate: GatewayEventHandler = async ( - gateway: Gateway, - d: GuildRoleCreatePayload -) => { - const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) - // Weird case, shouldn't happen - if (guild === undefined) return - - await guild.roles.set(d.role.id, d.role) - const role = await guild.roles.get(d.role.id) - gateway.client.emit('guildRoleCreate', role) +import { Gateway, GatewayEventHandler } from '../index.ts' +import { Guild } from '../../structures/guild.ts' +import { GuildRoleCreatePayload } from "../../types/gateway.ts" +import { Role } from "../../structures/role.ts" + +export const guildRoleCreate: GatewayEventHandler = async ( + gateway: Gateway, + d: GuildRoleCreatePayload +) => { + const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) + // Weird case, shouldn't happen + if (guild === undefined) return + + await guild.roles.set(d.role.id, d.role) + const role = await guild.roles.get(d.role.id) + gateway.client.emit('guildRoleCreate', (role as unknown) as Role) } \ No newline at end of file diff --git a/src/gateway/handlers/guildRoleUpdate.ts b/src/gateway/handlers/guildRoleUpdate.ts index af271f6..4ef01ed 100644 --- a/src/gateway/handlers/guildRoleUpdate.ts +++ b/src/gateway/handlers/guildRoleUpdate.ts @@ -1,21 +1,22 @@ -import { Gateway, GatewayEventHandler } from '../index.ts' -import { Guild } from '../../structures/guild.ts' -import { GuildRoleUpdatePayload } from "../../types/gateway.ts" - -export const guildRoleUpdate: GatewayEventHandler = async ( - gateway: Gateway, - d: GuildRoleUpdatePayload -) => { - const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) - // Weird case, shouldn't happen - if (guild === undefined) return - - const role = await guild.roles.get(d.role.id) - await guild.roles.set(d.role.id, d.role) - const newRole = await guild.roles.get(d.role.id) - - // Shouldn't happen either - if(role === undefined) return gateway.client.emit('guildRoleUpdateUncached', newRole) - - gateway.client.emit('guildRoleUpdate', role, newRole) +import { Gateway, GatewayEventHandler } from '../index.ts' +import { Guild } from '../../structures/guild.ts' +import { GuildRoleUpdatePayload } from "../../types/gateway.ts" +import { Role } from "../../structures/role.ts" + +export const guildRoleUpdate: GatewayEventHandler = async ( + gateway: Gateway, + d: GuildRoleUpdatePayload +) => { + const guild: Guild | undefined = await gateway.client.guilds.get(d.guild_id) + // Weird case, shouldn't happen + if (guild === undefined) return + + const role = await guild.roles.get(d.role.id) + await guild.roles.set(d.role.id, d.role) + const newRole = await guild.roles.get(d.role.id) + + // Shouldn't happen either + if(role === undefined) return gateway.client.emit('guildRoleUpdateUncached', newRole) + + gateway.client.emit('guildRoleUpdate', role, (newRole as unknown) as Role) } \ No newline at end of file