general.py 698 B

12345678910111213141516171819202122232425
  1. from discord.ext import commands
  2. import time
  3. async def setup(bot: commands.Bot):
  4. await bot.add_cog(GeneralCommands(bot))
  5. class GeneralCommands(commands.Cog):
  6. """General functionality."""
  7. def __init__(self, bot: commands.Bot):
  8. self.bot = bot
  9. @commands.command(
  10. description="Get the bot's current websocket and API latency.",
  11. brief="Test latency",
  12. help="Test latency by polling the gateway and API."
  13. )
  14. async def ping(self, ctx: commands.Context):
  15. start_time = time.time()
  16. message = await ctx.send(f"Pong!\nGateway heartbeat in {round(self.bot.latency * 1000)}ms.")
  17. end_time = time.time()
  18. await ctx.send(f"API roundtrip latency {round((end_time - start_time) * 1000)}ms.")