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

使用discord.Client()报错缺少intents参数,求助解决方法

解决discord.Client()缺少'intents'参数的报错问题

这个报错是因为Discord.py v2.0及以上版本强制要求传入Intents参数,你参考的旧教程基于v1.x版本,当时无需该参数。按以下步骤解决:

1. 在代码中添加Intents配置

修改代码,先创建Intents实例并启用必要权限,再传入Client():

import discord

# 创建默认意图实例,包含基础权限
intents = discord.Intents.default()
# 如果你的机器人需要读取消息内容,必须启用这个(后续还要在开发者后台开启对应权限)
intents.message_content = True

# 把intents参数传给Client
client = discord.Client(intents=intents)

# 后续事件处理代码保持不变
@client.event
async def on_ready():
    print(f'Logged in as {client.user}')

2. 在Discord开发者后台开启特权意图(若需读取消息)

如果机器人需要处理消息内容,必须在Discord开发者门户开启对应权限:

  • 进入你的Discord应用后台,切换到「Bot」标签页
  • 滚动到「Privileged Gateway Intents」区域,开启「Message Content Intent」

3. 确保discord.py版本为最新版

在repl.it的终端执行以下命令更新依赖:

pip install -U discord.py

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 08:50:22