Discord python 如何编写 ping 命令

Discord python How to programm a ping command

所以我正在尝试通过 python 和 discord 编写一个 ping 命令。问题是,在尝试了一堆方法之后,我仍然不知道它是如何工作的。如果有人能帮助我,我将不胜感激。

如果您正在使用 discord.py 重写命令扩展,您可以 bot.latency 其中 returns 一个浮点数。

import discord
import time

from time import 
time_then = time.monotonic()
pinger = await client.send_message(message.channel, '__*`Pinging...`*__')
ping = '%.2f' % (1000*(time.monotonic()-time_then))
await client.edit_message(pinger, ':ping_pong: \n **Pong!** __**`' + ping + 'ms`**__') # you can edit this to say whatever you want really. Hope this helps.