首页 > 解决方案 > 我怎么能解决这个 addrole 问题,因为我不知道怎么解决?

问题描述

我写了一个我在stackOverflow和idk某处找到的代码,当有人加入时我得到了这个错误,它没有给任何人一个角色

我试图更改命令,我试图寻求帮助,但没有人能帮助我

});
bot.on('guildMemberAdd', member => {
    console.log('User' + member.user.tag + 'has joined the server!');

    var role = member.guild.roles.find('name', 'user');
    member.addRole();
});

想知道怎么解决

Useranimeclone#0900has joined the server!
(node:4716) DeprecationWarning: Collection#find: pass a function instead
    at GuildMember.addRole (C:\Users\matti\Downloads\discordbot\node_modules\discord.js\src\structures\GuildMember.js:452:38)
    at CommandoClient.bot.on.member (C:\Users\matti\Downloads\discordbot\index.js:41:12)
    at CommandoClient.emit (events.js:198:13)
    at Guild._addMember (C:\Users\matti\Downloads\discordbot\node_modules\discord.js\src\structures\Guild.js:1192:19)
    at GuildMemberAddHandler.handle (C:\Users\matti\Downloads\discordbot\node_modules\discord.js\src\client\websocket\packets\handlers\GuildMemberAdd.js:12:13)
    at WebSocketPacketManager.handle (C:\Users\matti\Downloads\discordbot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
    at WebSocketConnection.onPacket (C:\Users\matti\Downloads\discordbot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
    at WebSocketConnection.onMessage (C:\Users\matti\Downloads\discordbot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
    at WebSocket.onMessage (C:\Users\matti\Downloads\discordbot\node_modules\ws\lib\event-target.js:120:16)
    at WebSocket.emit (events.js:198:13)
(node:4716) 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(). (rejection id: 1)(node:4716) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

标签: javascriptdiscord.js

解决方案


var role = member.guild.roles.find('name', 'user');

改成这样就好了

var role = member.guild.roles.find(role => role.name === 'user');

推荐阅读