试图将Autorole添加到我的机器人中,但出现TypeError:fn.bind不是函数

时间:2020-06-05 08:39:32

标签: discord.js

我刚开始使用JavaScript进行编码,而我正在编码discord.js。我一直在尝试添加自动角色功能,以便当有人加入不和谐服务器时,他们会自动获得默认角色。但是,由于所有教程或其他解释它的代码通常都是过时的,所以我一直在努力。因此,当我尝试运行机器人时,会收到此错误消息。

TypeError: fn.bind is not a function
  at Map.find (C:\Users\stuar\Desktop\Discord Bot\node modulesN^discordjs\collection\dist\index.js:158:21) at Client.<anonymous> (C:\Users\stuar\Desktop\Discord Bot\index.js:71:41)
  at Client.emit (events.js:327:22)
  at Object.module.exports [as GUILD_MEMBER_ADD] (C:\Users\stuar\Desktop\Discord Bot\node modules\discord.js\src\client\websocket\handlers\GUILD MEMBER ADD.js:16:14)
  at WebSocketManager. handlePacket (C : \Users\stuar\Desktop\Discord Bot \node_modules\discordjs\src\client \websocket \WebSocketManager. j s : 386:31 )
  at WebSocketShard.onPacket (C:\Users\stuar\Desktop\Discord Bot\node modules\discord.j s\src\client\websocket\WebSocketShard.js:436:22)
  at WebSocketShard.onMessage (C:\Users\stuar\Desktop\Discord Bot\node modules\discord.js\src\client\websocket\WebSocketShard.js: 293:10)
  at WebSocket.onMessage (C:\Users\stuar\Desktop\Discord Bot\node_modules\ws\lib\event-target.js:125:16)
  at WebSocket.emit (events.js:315:29)
  at Receiver.receiverOnMessage (C:\Users\stuar\Desktop\Discord Bot\node_modules\ws\lib\websocket.js: 800:20)

这是我似乎不喜欢的代码:

// Auto Role
client.on('guildMemberAdd", member => {
  console.log("User " + member.user.tag + " has joined the server!");
  var role = member.guild.roles.cache.find("name", "User");
  member.addRole(role);
});

1 个答案:

答案 0 :(得分:1)

您正在使用旧版本的||:在当前版本中,不再支持使用Collection.find()的“属性值”方式,您需要提供一个函数。您可以找到文档here
编码方法如下:

.find

另外,您可能已经注意到,由于GuildMember.addRole()是v11中的一种方法,因此您还需要编写client.on('guildMemberAdd', member => { let role = member.guild.roles.cache.find(r => r.name == 'User') member.roles.add(role) })