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) { if (hasGuild === undefined) {
// It wasn't lazy load, so emit event // It wasn't lazy load, so emit event
gateway.client.emit('guildCreate', guild) 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 * @param guild The new Guild object
*/ */
guildCreate: [guild: Guild] 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 * A Guild in which Client was either deleted, or bot was kicked
* @param guild The Guild object * @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( const arr = await (this.client.cache.array(
this.cacheName this.cacheName
) as ChannelPayload[]) ) as ChannelPayload[])
if (arr === undefined) return []
const result: any[] = [] const result: any[] = []
for (const elem of arr) { for (const elem of arr) {
let guild let guild

View file

@ -1,9 +1,5 @@
import { Collection } from '../utils/collection.ts' import { Collection } from '../utils/collection.ts'
import { import { connect, Redis, RedisConnectOptions } from '../../deps.ts'
connect,
Redis,
RedisConnectOptions
} from '../../deps.ts'
/** /**
* ICacheAdapter is the interface to be implemented by Cache Adapters for them to be usable with Harmony. * 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', () => { client.on('ready', () => {
console.log(`Logged in as ${client.user?.tag}!`) console.log(`Logged in as ${client.user?.tag}!`)
client.guilds.get('783319033205751809').then((guild) => { })
if (guild === undefined) return console.log('Guild not found')
guild client.on('guildLoaded', async (guild) => {
.chunk({ presences: true }, true) if (guild.id !== '783319033205751809') return
.then((guild) => { const arr = await guild.channels.array()
console.log(`Chunked guild:`, guild.id) console.log(arr.length)
}) guild
.catch((e) => { .chunk({ presences: true }, true)
console.log(`Failed to Chunk: ${guild.id} - ${e}`) .then((guild) => {
}) console.log(`Chunked guild:`, guild.id)
}) })
.catch((e) => {
console.log(`Failed to Chunk: ${guild.id} - ${e}`)
})
}) })
console.log('Connecting...') console.log('Connecting...')