| 3 | class PingCommand extends Command { |
| 4 | // help |
| 5 | async run() { |
| 6 | if (this.type === "classic") { |
| 7 | if (!this.message) throw Error("No message found"); |
| 8 | const pingMessage = await this.client.rest.channels.createMessage( |
| 9 | this.message.channelID, |
| 10 | Object.assign( |
| 11 | { |
| 12 | content: `🏓 ${this.getString("commands.responses.ping.ping")}`, |
| 13 | }, |
| 14 | this.reference, |
| 15 | ), |
| 16 | ); |
| 17 | let shard; |
| 18 | if (this.message.guildID) { |
| 19 | const guildShard = this.client.guildShardMap.get(this.message.guildID); |
| 20 | if (guildShard !== undefined) shard = this.client.shards.get(guildShard); |
| 21 | } |
| 22 | await pingMessage.edit({ |
| 23 | content: `🏓 ${this.getString("commands.responses.ping.pong")} |
| 24 | \`\`\` |
| 25 | ${this.getString("commands.responses.ping.latency", { |
| 26 | params: { |
| 27 | latency: Math.abs(pingMessage.timestamp.getTime() - this.message.timestamp.getTime()).toString(), |
| 28 | }, |
| 29 | })} |
| 30 | ${ |
| 31 | shard |
| 32 | ? `${this.getString("commands.responses.ping.shardLatency", { |
| 33 | params: { |
| 34 | latency: Math.round(shard.latency).toString(), |
| 35 | }, |
| 36 | })}\n` |
| 37 | : "" |
| 38 | }\`\`\``, |
| 39 | }); |
| 40 | } else { |
| 41 | if (!this.interaction) throw Error("No interaction found"); |
| 42 | const pingMessage = await this.interaction.getOriginal(); |
| 43 | let shard; |
| 44 | if (this.interaction.guildID) { |
| 45 | const guildShard = this.client.guildShardMap.get(this.interaction.guildID); |
| 46 | if (guildShard !== undefined) shard = this.client.shards.get(guildShard); |
| 47 | } |
| 48 | const created = new Date(Number(BigInt(this.interaction.id) / 4194304n + 1420070400000n)); |
| 49 | return `🏓 ${this.getString("commands.responses.ping.pong")} |
| 50 | \`\`\` |
| 51 | ${this.getString("commands.responses.ping.latency", { |
| 52 | params: { |
| 53 | latency: Math.abs(pingMessage.timestamp.getTime() - created.getTime()).toString(), |
| 54 | }, |
| 55 | })} |
| 56 | ${ |
| 57 | shard |
| 58 | ? `${this.getString("commands.responses.ping.shardLatency", { |
| 59 | params: { |
| 60 | latency: Math.round(shard.latency).toString(), |
| 61 | }, |
| 62 | })}\n` |