20 lines
832 B
TypeScript
20 lines
832 B
TypeScript
import { TextChannel } from '../../structures/textChannel.ts'
|
|
import { MessageDeletePayload } from '../../types/gateway.ts'
|
|
import type { Gateway, GatewayEventHandler } from '../mod.ts'
|
|
|
|
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)
|
|
gateway.client.emit('messageDelete', message)
|
|
}
|