diff --git a/README.md b/README.md index 0f20c2e..c987f5c 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ client.on('ready', () => { // Listen for event whenever a Message is sent client.on('messageCreate', (msg: Message): void => { if (msg.content === '!ping') { - msg.channel.send(`Pong! WS Ping: ${client.ping}`) + msg.channel.send(`Pong! WS Ping: ${client.gateway.ping}`) } }) @@ -95,7 +95,7 @@ class PingCommand extends Command { name = 'ping' execute(ctx: CommandContext) { - ctx.message.reply(`pong! Ping: ${ctx.client.ping}ms`) + ctx.message.reply(`pong! Ping: ${ctx.client.gateway.ping}ms`) } } diff --git a/src/client/client.ts b/src/client/client.ts index 317265d..457d77b 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -78,8 +78,6 @@ export class Client extends HarmonyEventEmitter { rest: RESTManager /** User which Client logs in to, undefined until logs in */ user?: User - /** WebSocket ping of Client */ - ping = 0 /** Token of the Bot/User */ token?: string /** Cache Adapter */ diff --git a/src/gateway/mod.ts b/src/gateway/mod.ts index 8cb7f34..6764095 100644 --- a/src/gateway/mod.ts +++ b/src/gateway/mod.ts @@ -66,6 +66,7 @@ export class Gateway extends HarmonyEventEmitter { cache: GatewayCache private timedIdentify: number | null = null shards?: number[] + ping: number = 0 constructor(client: Client, shards?: number[]) { super() @@ -115,11 +116,9 @@ export class Gateway extends HarmonyEventEmitter { case GatewayOpcodes.HEARTBEAT_ACK: this.heartbeatServerResponded = true - this.client.ping = Date.now() - this.lastPingTimestamp - this.emit('ping', this.client.ping) - this.debug( - `Received Heartbeat Ack. Ping Recognized: ${this.client.ping}ms` - ) + this.ping = Date.now() - this.lastPingTimestamp + this.emit('ping', this.ping) + this.debug(`Received Heartbeat Ack. Ping Recognized: ${this.ping}ms`) break case GatewayOpcodes.INVALID_SESSION: diff --git a/test/index.ts b/test/index.ts index a2cdd18..872f457 100644 --- a/test/index.ts +++ b/test/index.ts @@ -60,7 +60,7 @@ client.on('messageCreate', async (msg: Message) => { console.log(`${msg.author.tag}: ${msg.content}`) } if (msg.content === '!ping') { - msg.reply(`Pong! Ping: ${client.ping}ms`) + msg.reply(`Pong! Ping: ${client.gateway.ping}ms`) } else if (msg.content === '!members') { const col = await msg.guild?.members.array() const data = col