我在ping命令中遇到bot.latency问题。
首先,我这样声明我的机器人实例:
bot = commands.Bot(
description='Genos Bot Help Section - prefix: ^ ',
command_prefix='^',
case_insensitive=True,
guild_subscriptions=True,
intents=intents
) # I have this in one line in my program, but I wrote it like that in order to be easily read.
之后,我输入ping命令:
# I used commands.command because I have cogs for my discord bot.
@commands.command(name="ping")
async def ping(self, ctx: commands.Context):
"""Ping command!"""
await ctx.send(f'Pong! {round(bot.latency * 1000)} ms')
bot.latency
的问题在于尽管nan
的文档编写方式如何,但它仍返回float
,并且无法进行转换,从而给我以下错误:
ValueError: cannot convert float NaN to integer
我该如何解决这个问题?