javascript - 我怎么能解决这个 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.
解决方案
var role = member.guild.roles.find('name', 'user');
改成这样就好了
var role = member.guild.roles.find(role => role.name === 'user');
推荐阅读
- javascript - 我想知道如何在提交表单后清除输入字段,因为我阻止了页面刷新
- spring - Spring Boot - Keycloak:“无法将代码转换为令牌” SSL
- api - 我可以从 Instagram 图片网址获取用户 ID 吗?
- vbscript - IBM PCOMM - 无法从另一个 vbs 宏中调用 vbs 宏
- scala - 如何使用 Scala 在 Akka Actor 中查找意外消息的来源
- sql - SQL - 如何删除两个相互引用的实体
- r - 在R中将字符日期(“01OCT2014”)转换为DATE格式
- php - 读取 CSV 文件的行并将值放入数组
- html - 如何修复 Codepen 中的锚点问题:“Bad path /boomboom/v2
- java - 如何注入在 Guice 中使用辅助注入创建的对象?