在我的不和谐机器人中,我试图制作一个 add command
,因此它添加了 member
自我角色。
我知道如何将 roles
添加到 member
但我不知道如何添加 member
的 role
是mentioned
!
这是我目前的代码:
if (msg.content.startsWith(prefix + 'add')) {
let rolename = msg.content.slice(5).trim()
let role = msg.guild.roles.cache.find(r => r.name === rolename)
//The code will work if the member only types the name of the role without mention
//so it is also a solution if someone knows how to change the mention to a name
msg.member.roles.add(role)
}
答案 0 :(得分:1)
使用 message
对象的 mentions 属性并检查 mention
中是否包含 role
。
如果是,则存储该值,然后将其添加到 member
。而 <MessageMentions>#roles#first()
会为您提供 first mentioned role
集合中的 roles
。