我创建了一个 ping 命令,使用以下代码响应机器人延迟:
# To ping the bot (latency)
@commands.command()
async def ping(self, ctx):
try:
latency = round(client.latency * 1000, 1)
await ctx.send(f"Pong! Latency: {latency}ms")
except:
await ctx.send(f"Error getting latency")
然而,机器人回复“Pong!Latency:nanms”,而不是“Pong!Latency:ms”我没有发现代码有任何错误,但出于某种原因,它说这不是数字.你能帮我找出错误吗?
答案 0 :(得分:1)
用这个修改
@commands.command()
async def ping(self,ctx):
await ctx.send(f"**{round(self.bot.latency * 1000)}** ms"))
这不是客户端延迟,而是 self.bot.latency
答案 1 :(得分:1)
将您的命令替换为:
@commands.command()
async def ping(self,ctx):
await ctx.send(f"Pong! Latency:*{round(self.client.latency * 1000)} ms"))