harmony/src/gateway/handlers/messageDelete.ts

21 lines
842 B
TypeScript
Raw Normal View History

2021-04-04 09:29:56 +00:00
import type { TextChannel } from '../../structures/textChannel.ts'
import type { MessageDeletePayload } from '../../types/gateway.ts'
2021-04-04 05:42:15 +00:00
import type { Gateway, GatewayEventHandler } from '../mod.ts'
2020-12-02 12:29:52 +00:00
export const messageDelete: GatewayEventHandler = async (
gateway: Gateway,
d: MessageDeletePayload
) => {
let channel = await gateway.client.channels.get<TextChannel>(d.channel_id)
// Fetch the channel if not cached
if (channel === undefined)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
channel = (await gateway.client.channels.fetch(d.channel_id)) as TextChannel
const message = await channel.messages.get(d.id)
if (message === undefined)
return gateway.client.emit('messageDeleteUncached', d)
await channel.messages._delete(d.id)
2020-12-02 12:29:52 +00:00
gateway.client.emit('messageDelete', message)
}