Discord python如何编写ping命令

时间:2017-11-18 22:36:07

标签: python-3.x discord.py

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

2 个答案:

答案 0 :(得分:0)

如果你使用带有命令扩展名的discord.py重写,你可以bot.latency返回一个浮点数。

答案 1 :(得分:0)

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.