general.py 732 B

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