python - 我的机器人没有以正确的延迟回复
问题描述
我创建了一个 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!延迟:nanms”,而不是“Pong!延迟:ms”我没有发现代码有任何错误,但由于某种原因,它说它不是数字。你能帮我找出错误吗?
解决方案
用这个修改
@commands.command()
async def ping(self,ctx):
await ctx.send(f"**{round(self.bot.latency * 1000)}** ms"))
不会是客户端延迟,而是self.bot.latency
推荐阅读
- gnuplot - 如何在gnuplot中并排放置两个带有插图的图?
- node.js - 在 socket.io-client reactjs 中多次发出相同的事件
- python - import cv2 dll load failed: 找不到指定的模块
- exception - 在 Airflow 中传递异常
- javascript - jquery 函数甚至可以从不同的按钮一起执行
- java - 当接口没有它时,访问抽象类中的方法的最佳方法是什么?
- javascript - 如何使用函数通过线性渐变更改背景颜色?
- html - 并排放置两个块元素
- spring-boot - 使用数据库发送 Spring 实时数据
- python-3.x - 初学者:不明白我的代码的错误在哪里