我的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我该如何解决这个问题?
发布于 2022-10-23 14:28:32
很容易修好!
因为您使用的是齿轮,所以需要self。
这应该可以解决您的问题:
await ctx.send(f'Pong! {round(self.bot.latency * 1000)} ms')整个代码:
@commands.command(name="ping")
async def ping(self, ctx: commands.Context):
"""Ping command!"""
await ctx.send(f'Pong! {round(self.bot.latency * 1000)} ms')https://stackoverflow.com/questions/64782743
复制相似问题