You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discord Bot报错:'Bot'对象无'Latency'属性,寻求解决方案

解决discord.py中Bot对象无Latency属性的错误

问题出在Python的大小写敏感性上——discord.py的Bot类提供的WebSocket延迟属性是小写的latency,而非你代码里写的大写开头的Latency。

修正后的代码如下:

import discord
from discord.ext import commands, tasks

intents = discord.Intents.all()
intents.message_content = True

client = commands.Bot(command_prefix = "+", intents=intents)

@client.command(name="ping", help="This is a ping command")
async def ping(ctx):
     await ctx.send(f"**Pong** Latency: {round(client.latency * 1000)}ms")

补充说明:client.latency返回的是WebSocket连接的延迟值(单位为秒),乘以1000转换为毫秒的处理是正确的,修正后执行+ping命令就能正常返回延迟数据了。

内容的提问来源于stack exchange,提问作者Phoenix

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 13:35:17