无法通过 Discord 机器人的反应角色添加角色

trouble adding roles through reaction role for my discord bot

提问人:XMr_ReaperX 提问时间:11/16/2023 更新时间:11/16/2023 访问量:31

问:

所以我试图设置一个反应角色命令,但我得到错误:

*DiscordAPIError: Missing Permissions
    at RequestHandler.execute (C:\Users\mreap\Desktop\orbit project, etc\box militia\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\mreap\Desktop\orbit project, etc\box militia\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async GuildMemberRoleManager.add (C:\Users\mreap\Desktop\orbit project, etc\box militia\node_modules\discord.js\src\managers\GuildMemberRoleManager.js:124:7) {
  method: 'put',
  path: '/guilds/1015814032088891462/members/1173097778843496620/roles/1015880336665743382',  
  code: 50013,
  httpStatus: 403,
  requestData: { json: undefined, files: [] }
}*

我的代码看起来像这样,如果您有任何见解,请帮助我:

const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MESSAGE_REACTIONS"] });

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}`);
});

client.on('messageCreate', async (message) => {
  if (message.content === '!reaction_role') {
    const reactionMessage = await message.channel.send('React to this message to get the role!');
    reactionMessage.react('✅');
  }
});

client.on('messageReactionAdd', async (reaction, user) => {
  if (reaction.emoji.name === '✅') {
    const guild = reaction.message.guild;
    const member = guild.members.cache.get(user.id);
    let role = guild.roles.cache.find(role => role.name === 'test'); // Replace YOUR_ROLE_NAME with the name of the role you want to assign
    member.roles.add(role.id);
  }
});

client.login('token');

` 我在其他页面上阅读似乎没有任何效果,我重写了我尝试过的所有代码 youtube 反应角色不想为我工作,机器人有权限,它是管理员,机器人角色位于所有其他角色之上

节点.js 和谐 不和谐.js 节点模块

评论

0赞 Matze._ 11/16/2023
从 discord 开发人员门户启用 (Privileged Gateway Intents) 并导入 Intents.FLAGS。(您需要的意图)
0赞 Matze._ 11/16/2023
prnt.sc/aavoX_zeJRzD
0赞 XMr_ReaperX 11/16/2023
这已经在 Discord 开发人员上完成,我想我已经在上面声明了意图,或者有其他方法可以做到这一点吗?这就是我认为我声明意图的方式,如果它是错误的,我该如何解决?const client = new Discord.Client({ intents: [“公会”, “GUILD_MESSAGES”, “GUILD_MESSAGE_REACTIONS”] });@Matze._
0赞 Matze._ 11/16/2023
是的,对不起,忽略了这一点。错误代码:50013 表示您无权执行该操作。您确定已设置机器人所需的所有权限,它位于角色列表的顶部并具有管理员角色吗?
0赞 Zsolt Meszaros 11/16/2023
您能为我们登录吗?console.log(guild.me.roles.highest.position, member.roles.highest.position)member.roles.add(role.id)

答: 暂无答案