简体   繁体   English

如何修复 ValueError: cannot convert float NaN to integer 错误 discord cog 与 python?

[英]How do I fix the ValueError: cannot convert float NaN to integer error for discord cog with python?

I get this error for my ping command.我的 ping 命令出现此错误。

await ctx.send(f"Pong! {round(client.latency * 1000)}ms")
ValueError: cannot convert float NaN to integer

The actual ping/latency part does not display itself in Discord when the command is entered.输入命令时,实际的 ping/延迟部分不会显示在 Discord 中。 However, if I remove the curly braces part, it displays Pong just fine.但是,如果我删除花括号部分,它会很好地显示 Pong。

This is my whole code (It is in a cog):这是我的整个代码(它在一个齿轮中):

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = "oof ")

class Other(commands.Cog):

    def __init__(self, client):
        self.client = client

    # Events
    @commands.Cog.listener()
    async def on_ready(self):
        print("Ping is ready.")

    # Commands
    @commands.command()
    async def ping(self, ctx):
        await ctx.send(f"Pong! {round(client.latency * 1000)}ms")

def setup(client):
    client.add_cog(Other(client))

Try using this:尝试使用这个:

@commands.command()
async def ping(self, ctx):
    await ctx.send(f"Pong! {round(self.client.latency * 1000)}ms")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否有可能在不删除NaN值的情况下修复“ ValueError:无法将float NaN转换为整数”错误? - Is it possible to fix 'ValueError: cannot convert float NaN to integer' error without removing the NaN values? Numpy:ValueError:无法将浮点 NaN 转换为整数(Python) - Numpy: ValueError: cannot convert float NaN to integer (Python) 得到这个错误 ValueError: cannot convert float NaN to integer - Got this Error ValueError: cannot convert float NaN to integer 出现错误:ValueError:无法将浮点 NaN 转换为 integer - Getting error: ValueError: cannot convert float NaN to integer 错误如下: ValueError: cannot convert float NaN to integer - The error is the following: ValueError: cannot convert float NaN to integer Pandas:ValueError:无法将浮点 NaN 转换为整数 - Pandas: ValueError: cannot convert float NaN to integer 解决 ValueError:无法将浮点 NaN 转换为整数 - Solving ValueError: cannot convert float NaN to integer ValueError:无法将浮点 NaN 转换为整数” - ValueError: cannot convert float NaN to integer" 如何修复这个python错误? 溢出错误:无法将浮点无穷大转换为整数 - How to fix this python error? OverflowError: cannot convert float infinity to integer Pandas Read_Parquet NaN 错误:ValueError:无法将浮点 NaN 转换为 integer - Pandas Read_Parquet NaN error: ValueError: cannot convert float NaN to integer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM