【发布时间】:2020-09-19 14:51:21
【问题描述】:
我正在尝试编写一个机器人,当用户加入服务器时,它会为他添加角色“Banda canina”,我试图给他一个管理员角色,但它继续给出这个错误。这是代码
bot.on('guildMemberAdd', member => {
let wChannel = member.guild.channels.cache.find(channel => channel.name === botConfig.canale_benvenuto);
if(!wChannel) return console.log('Canale di log non valido');
let wRole = member.guild.roles.cache.find(role => role.name === botConfig.ruolo_base);
if(!wRole) return console.log('Impossibile trovare il ruolo base');
wChannel.send(`${member.user.username}#${member.user.discriminator} è entrato nel server`);
member.roles.add(wRole);
});
我在另一台测试服务器上尝试了该机器人,它可以工作,但在主服务器上却不行。这是完整的错误:
UnhandledPromiseRejectionWarning: DiscordAPIError: Missing Permissions
at RequestHandler.execute (C:\Users\Pc\Desktop\Bot Gio\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:8268) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
【问题讨论】:
-
您说您尝试赋予机器人管理员角色,但管理员角色实际上是否具有管理员权限?查看管理员角色的内部设置,看看是否检查了
administrator或任何它的名称。然后点击channel.name === botConfig.canale_benvenuto的频道,看看bot有没有 -
我控制了,管理员权限被检查,bot在频道
channel.name === botConfig.canale_benvenuto
标签: javascript discord.js