javascript - 如何将提到的角色添加到成员?
问题描述
在我的不和谐机器人中,我试图制作一个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)
}
解决方案
使用对象的mentions属性message
并检查其中是否mention
有a role
。
如果是,则存储该值,然后将其添加到member
. 并且<MessageMentions>#roles#first()
会给你first mentioned role
来自集合的roles
。
推荐阅读
- linux - 过滤器快照版本
- amazon-web-services - 如何使用 API Gateway 中的请求验证器验证请求正文中的所需参数?
- java - 为什么默认方法不被识别为属性(getter/setter)?
- c++ - 在 C++ 中,如何在头文件中为类和函数编写完整的实现(可能是模板化的)
- charts - 添加 xAxes 时图表 JS 未显示
- python - ajax 像按钮 django
- reactjs - 控制台错误“未捕获的错误:在 webpackMissingModule 上找不到模块“/axios”并做出反应
- linux - 看不到上传的图片
- sharepoint - 什么是用于为 SharePoint 中的文件夹获取子项的 MS Graph API?
- c - file-nr 和 /proc/ 之间的区别
/fd/*