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

Discord.py用户信息命令获取用户状态全部显示离线问题求助

问题原因

这个问题是Discord API v1.5及以上版本引入的**网关意图(Intents)**限制导致的:用户状态、服务器成员列表这类敏感数据默认不向机器人开放,需要手动开启对应权限。

修复步骤

  1. 打开Discord开发者门户,进入你当前机器人的管理页,在「Bot」设置板块下找到Privileged Gateway Intents区域,开启Presence Intent和Server Members Intent两个开关。
  2. 修改你的代码初始化逻辑,显式声明需要启用的意图:
import discord
from discord.ext import commands

# 声明需要的意图
intents = discord.Intents.default()
intents.presences = True # 开启用户状态获取权限
intents.members = True # 开启服务器成员信息获取权限

# 初始化client时传入意图配置,替换你原来的client初始化代码即可
client = commands.Bot(command_prefix='你的命令前缀', intents=intents)

# 你原来的info命令代码不需要修改
@client.command(aliases=["userinfo"] ,help = "Finds info about users on the discord.")
async def info(ctx, user: discord.Member):
    embed = discord.Embed(title=f"{user}'s info", description=f"Here's {user}'s info", color=0x00ff00)
    embed.add_field(name="Username:", value=user.name, inline=True)
    embed.add_field(name="ID:", value=user.id, inline=True)
    embed.add_field(name="Status:", value=user.status, inline=True)
    embed.add_field(name="Highest Role:", value=user.top_role, inline=True)
    embed.add_field(name="Joined:", value=user.joined_at, inline=True)
    embed.set_thumbnail(url=user.avatar_url)
    await ctx.send(embed=embed)

注意事项

如果你的机器人已经加入超过100个服务器,需要向Discord提交验证申请才能启用上述两个特权意图,未达100服的机器人直接开启开关即可正常使用。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 02:36:04