adding ping command for the slash test

This commit is contained in:
Mylloon 2021-05-28 14:10:05 +02:00
parent b1f2e3ad39
commit 8096305121

View file

@ -1,4 +1,5 @@
import discord
import time
from discord.ext import commands
from discord_slash import cog_ext, SlashContext
@ -11,7 +12,12 @@ class Slash(commands.Cog):
def __init__(self, client):
self.client = client
@cog_ext.cog_slash(name="test")
async def _test(self, ctx: SlashContext):
embed = discord.Embed(title="embed test")
await ctx.send(content="test", embeds=[embed])
@cog_ext.cog_slash(name="pingSlash", description = "Affiche mon ping.")
async def _pingSlash(self, ctx: SlashContext):
now = int(round(time.time() * 1000))
ping = now - int(round(ctx.message.created_at.timestamp() * 1000))
embed = discord.Embed(description = 'Pinging...')
message = await ctx.send(embed = embed)
ping2 = int(round(time.time() * 1000)) - now
await message.edit(embed = discord.Embed(color = discord.Colour.random(), description = f':hourglass: {round(self.client.latency * 1000)} ms\n\n:stopwatch: {ping2} ms\n\n:heartbeat: {ping} ms'))
await ctx.message.add_reaction(emoji = '')