Skip to content

Ping

Bases: Cog

Source code in src\cogs\ping.py
class Ping(commands.Cog):

    def __init__(self, bot: commands.Bot) -> None:
        """
        Creates an instance of the Ping class.

        Args:
            bot (discord.ext.commands.Bot): The discord bot the command is
                                            being added to.
        """
        self.bot = bot

    @app_commands.command(name="ping", description="Checks the bot latency.")
    async def ping(self,
                   interaction: discord.Interaction,
                   show_latency: bool = True) -> None:
        """
        Pings the discord bot.

        Args:
            interaction (discord.Interaction): Represents the interaction
                                               from discord.
            show_latency (bool): Whether to display the latency in the reply
                                 or not.
        """
        message = "Pong..."
        if show_latency:
            message = f"Pong... {round(self.bot.latency, 4) * 1000}ms"
        try:
            await interaction.response.send_message(message)
        except Exception as e:
            nasa_bot_logger.exception(e)

__init__(bot)

Creates an instance of the Ping class.

Parameters:

Name Type Description Default
bot Bot

The discord bot the command is being added to.

required
Source code in src\cogs\ping.py
def __init__(self, bot: commands.Bot) -> None:
    """
    Creates an instance of the Ping class.

    Args:
        bot (discord.ext.commands.Bot): The discord bot the command is
                                        being added to.
    """
    self.bot = bot

ping(interaction, show_latency=True) async

Pings the discord bot.

Parameters:

Name Type Description Default
interaction Interaction

Represents the interaction from discord.

required
show_latency bool

Whether to display the latency in the reply or not.

True
Source code in src\cogs\ping.py
@app_commands.command(name="ping", description="Checks the bot latency.")
async def ping(self,
               interaction: discord.Interaction,
               show_latency: bool = True) -> None:
    """
    Pings the discord bot.

    Args:
        interaction (discord.Interaction): Represents the interaction
                                           from discord.
        show_latency (bool): Whether to display the latency in the reply
                             or not.
    """
    message = "Pong..."
    if show_latency:
        message = f"Pong... {round(self.bot.latency, 4) * 1000}ms"
    try:
        await interaction.response.send_message(message)
    except Exception as e:
        nasa_bot_logger.exception(e)