# commands/ping.py
from discord import Interaction, User
from discord.ext.commands import Bot, Cog
from discord.app_commands import command, describe
from utils.messages import message
from utils.logs import log
NAME: str = message("commands", "ping", "name")
DESCRIPTION: str = message("commands", "ping", "description")
USER: str = message("commands", "ping", "user")
class PingCommand(Cog):
def __init__(self, bot: Bot) -> None:
self.bot: Bot = bot
@command(name=NAME, description=DESCRIPTION)
@describe(user=USER)
async def ping(self, interaction: Interaction, user: User = None) -> None:
log("command", command=NAME, user_name=interaction.user.display_name)
try:
await self.command(interaction, user)
except Exception as error:
log("error", error=error)
async def command(self, interaction: Interaction, user: User) -> None:
if user is None:
user = interaction.user
response: str = message("commands", "ping", "response", user_id=user.id)
await interaction.response.send_message(response, ephemeral=True)
async def setup(bot: Bot) -> None:
await bot.add_cog(PingCommand(bot))