简体   繁体   English

新公会成员加入 Discord 公会时如何自动添加角色

[英]How to automatically add a role to a new guild member when they join a Discord guild

I have been trying for a quite a while to make a bot that should automatically give a certain role to any new user that joins my discord server and so far I haven't had any luck.我一直在尝试制作一个机器人,它应该自动为任何加入我的 discord 服务器的新用户赋予特定角色,但到目前为止我还没有运气。

client.on('guildMemberAdd', member => {
  console.log('User ' + member.user.username + ' has joined the server!')
  var role = member.guild.roles.cache.find(role => role.name === 'Alive and Clean');
  member.addRole(role)
});

I have encounted an error that is TypeError: member.addRole is not a function .我遇到了一个错误,即TypeError: member.addRole is not a function

Since discord.js v12 you now need to use roles.add() instead of addRole() .由于 discord.js v12 您现在需要使用roles.add()而不是addRole()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM