[英]Is it possible to fix 'ValueError: cannot convert float NaN to integer' error without removing the NaN values?
[英]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.