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

discord.py开发Discord机器人报错:缺少必填关键字参数'intents'

解决Discord机器人初始化缺失intents参数的问题

这个错误是因为Discord.py v2.0及以上版本强制要求初始化机器人时指定intents(意图)——这是Discord官方推出的权限机制,用来控制机器人能接收和处理哪些类型的事件数据,避免不必要的API请求和权限滥用。

修改后的代码:

import discord
from discord.ext import commands

# 初始化基础意图,并开启消息内容权限(执行ping命令需要接收用户消息)
intents = discord.Intents.default()
intents.message_content = True

# 初始化Bot时传入intents参数
bot = commands.Bot(command_prefix='0', intents=intents)

@bot.command(name='ping')
async def ping(ctx):
    await ctx.send('Pong!')

bot.run('MY_DISCORD_BOT_TOKEN')

额外说明:

  • 如果你的机器人需要其他功能(比如获取成员列表、监听成员状态变化),需要在代码里开启对应的intents,同时还要登录Discord开发者后台,在机器人页面的"Privileged Gateway Intents"板块开启对应的特权意图,否则机器人无法正常获取相关数据。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 23:02:02