Untitled
unknown
plain_text
a year ago
950 B
8
Indexable
import discord
from discord.ext import commands
# Define a Cog for handling ping commands
class Ping(commands.Cog):
def __init__(self, bot):
self.bot = bot
# Event called when the bot is ready
@commands.Cog.listener()
async def on_ready(self):
print(f"ping.py has successfully initialised.")
# Command to display bot latency
@commands.command()
async def ping(self, ctx):
# Get the bot's latency in milliseconds
bot_latency = round(self.bot.latency * 1000)
# Send the bot latency in the server's channel
await ctx.send(f"Pong! {bot_latency}ms.")
# Send the bot latency in a direct message to the user who issued the command
await ctx.author.send(f"Pong! {bot_latency}ms.")
# This function is required for Discord.py to recognize the cog
async def setup(bot):
await bot.add_cog(Ping(bot))
Editor is loading...
Leave a Comment