在终端运行Discord Bot时遭遇DisallowedIntents问题
解决Discord机器人DisallowedIntents错误
问题原因
你代码里用到的GuildMembers和MessageContent属于Discord的特权网关意图,这类意图默认处于关闭状态,必须在Discord开发者后台手动开启,否则会触发DisallowedIntents报错。
解决步骤
- 登录Discord开发者平台,找到你的机器人应用
- 进入「Bot」页面,滚动到「Privileged Gateway Intents」板块
- 开启「Server Members Intent」和「Message Content Intent」两个开关
- 重启机器人进程,让新的权限设置生效
代码确认
你的代码本身的意图配置没有问题,无需修改:
const { Client, GatewayIntentBits } = require("discord.js"); const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers ], }); client.login("TOKEN");
注:Guilds和GuildMessages属于普通意图,无需额外开启。
内容的提问来源于stack exchange,提问作者user17202586
相关产品推荐
相关产品推荐

