| 12345678910111213141516171819202122232425 |
- from discord.ext import commands
- import time
- async def setup(bot: commands.Bot):
- await bot.add_cog(GeneralCommands(bot))
- class GeneralCommands(commands.Cog):
- """General functionality."""
- def __init__(self, bot: commands.Bot):
- self.bot = bot
- @commands.command(
- description="Get the bot's current websocket and API latency.",
- brief="Test latency",
- help="Test latency by polling the gateway and API."
- )
- async def ping(self, ctx: commands.Context):
- start_time = time.time()
- message = await ctx.send(f"Pong!\nGateway heartbeat in {round(self.bot.latency * 1000)}ms.")
- end_time = time.time()
- await ctx.send(f"API roundtrip latency {round((end_time - start_time) * 1000)}ms.")
|