fix channels.array and add guildLoaded event

This commit is contained in:
DjDeveloperr 2021-01-01 10:30:11 +05:30
parent b344c2e24a
commit e3bce85f09
5 changed files with 22 additions and 17 deletions

View file

@ -30,5 +30,5 @@ export const guildCreate: GatewayEventHandler = async (
if (hasGuild === undefined) {
// It wasn't lazy load, so emit event
gateway.client.emit('guildCreate', guild)
}
} else gateway.client.emit('guildLoaded', guild)
}

View file

@ -154,6 +154,11 @@ export interface ClientEvents {
* @param guild The new Guild object
*/
guildCreate: [guild: Guild]
/**
* A Guild was successfully loaded.
* @param guild The Guild object
*/
guildLoaded: [guild: Guild]
/**
* A Guild in which Client was either deleted, or bot was kicked
* @param guild The Guild object

View file

@ -29,6 +29,7 @@ export class ChannelsManager extends BaseManager<ChannelPayload, Channel> {
const arr = await (this.client.cache.array(
this.cacheName
) as ChannelPayload[])
if (arr === undefined) return []
const result: any[] = []
for (const elem of arr) {
let guild

View file

@ -1,9 +1,5 @@
import { Collection } from '../utils/collection.ts'
import {
connect,
Redis,
RedisConnectOptions
} from '../../deps.ts'
import { connect, Redis, RedisConnectOptions } from '../../deps.ts'
/**
* ICacheAdapter is the interface to be implemented by Cache Adapters for them to be usable with Harmony.

View file

@ -7,17 +7,20 @@ client.on('debug', console.log)
client.on('ready', () => {
console.log(`Logged in as ${client.user?.tag}!`)
client.guilds.get('783319033205751809').then((guild) => {
if (guild === undefined) return console.log('Guild not found')
guild
.chunk({ presences: true }, true)
.then((guild) => {
console.log(`Chunked guild:`, guild.id)
})
.catch((e) => {
console.log(`Failed to Chunk: ${guild.id} - ${e}`)
})
})
})
client.on('guildLoaded', async (guild) => {
if (guild.id !== '783319033205751809') return
const arr = await guild.channels.array()
console.log(arr.length)
guild
.chunk({ presences: true }, true)
.then((guild) => {
console.log(`Chunked guild:`, guild.id)
})
.catch((e) => {
console.log(`Failed to Chunk: ${guild.id} - ${e}`)
})
})
console.log('Connecting...')