[英]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.