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

Python报错:__init__()缺少必填仅关键字参数'intents',如何解决?

解决discord.py中__init__() missing 1 required keyword-only argument: 'intents'错误

这个错误是因为discord.py 2.0及以上版本强制要求创建commands.Bot实例时必须指定intents参数,这是Discord API的权限控制机制,用来限定机器人能接收的事件类型。

修复步骤:

  1. 在代码中配置Intents
    导入discord.Intents,根据需求创建意图实例,再传给commands.Bot:

    import discord
    from discord.ext import commands
    
    # 启用默认意图,同时开启消息内容读取权限(如果需要处理消息命令)
    intents = discord.Intents.default()
    intents.message_content = True
    
    # 初始化Bot时传入intents参数
    blox = commands.Bot(command_prefix='!', intents=intents)
    

    如果你不需要全部默认权限,可以自定义开启特定意图:

    intents = discord.Intents.none()
    intents.guilds = True  # 必备:处理服务器相关事件
    intents.messages = True  # 接收消息事件
    intents.message_content = True  # 读取消息内容(需开发者后台开启)
    
  2. 在Discord开发者后台开启对应权限
    登录Discord开发者门户,进入你的机器人应用,在「Bot」选项卡下找到「Privileged Gateway Intents」,开启Message Content Intent(如果你的机器人需要读取消息内容来响应命令)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 02:10:57