繁体   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?

我的 ping 命令出现此错误。

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

输入命令时,实际的 ping/延迟部分不会显示在 Discord 中。 但是,如果我删除花括号部分,它会很好地显示 Pong。

这是我的整个代码(它在一个齿轮中):

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))

尝试使用这个:

@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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM