2020-10-30 14:51:40 +00:00
|
|
|
import { Gateway, GatewayEventHandler } from '../index.ts'
|
|
|
|
import getChannelByType from '../../utils/getChannelByType.ts'
|
2020-11-02 06:58:23 +00:00
|
|
|
import { ChannelPayload } from '../../types/channel.ts'
|
2020-11-11 09:04:49 +00:00
|
|
|
import { Guild } from "../../structures/guild.ts"
|
2020-10-30 14:51:40 +00:00
|
|
|
|
2020-11-01 11:22:09 +00:00
|
|
|
export const channelCreate: GatewayEventHandler = async (
|
2020-10-30 14:51:40 +00:00
|
|
|
gateway: Gateway,
|
2020-11-02 06:58:23 +00:00
|
|
|
d: ChannelPayload
|
2020-10-30 14:51:40 +00:00
|
|
|
) => {
|
2020-11-11 09:04:49 +00:00
|
|
|
const guild: undefined | Guild = (d as any).guild_id !== undefined ? await gateway.client.guilds.get((d as any).guild_id) : undefined
|
|
|
|
const channel = getChannelByType(gateway.client, d, guild)
|
2020-10-30 14:51:40 +00:00
|
|
|
if (channel !== undefined) {
|
2020-11-01 11:22:09 +00:00
|
|
|
await gateway.client.channels.set(d.id, d)
|
2020-10-30 14:51:40 +00:00
|
|
|
gateway.client.emit('channelCreate', channel)
|
|
|
|
}
|
|
|
|
}
|