Discord.py bot | bot.latency返回nan,尽管有浮点数

时间:2020-11-11 08:16:08

标签: python discord bots

我在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

我该如何解决这个问题?

0 个答案:

没有答案