Javascript 如何使用命令分配角色-discord.js
我想给我的机器人一个通过命令分配角色的功能 例如,Javascript 如何使用命令分配角色-discord.js,javascript,node.js,discord.js,Javascript,Node.js,Discord.js,我想给我的机器人一个通过命令分配角色的功能 例如,+mod@user将赋予@usermod的角色 mymain.js中的代码: if(command == 'mod'){ client.commands.get('mod').execute(message, args); } 我的mod.js文件中的代码: module.exports = { name: 'mod', description: "This command gives member the M
+mod@user
将赋予@user
mod的角色
mymain.js中的代码
:
if(command == 'mod'){
client.commands.get('mod').execute(message, args);
}
我的mod.js
文件中的代码:
module.exports = {
name: 'mod',
description: "This command gives member the Mod role",
execute(message, args){
const member = message.mentions.users.first();
member.roles.add('role ID xxxx');
}
}
我收到一个错误,说成员为空。我做错什么了吗?我不认为上面说
成员是空的<代码>用户
没有角色,成员
有角色。因此,您需要获得第一个
module.exports={
名称:“mod”,
description:'此命令赋予成员Mod角色',
异步执行(消息、参数){
const member=message.indications.members.first();
如果(!成员){
返回消息。回复('您需要提及某人');
}
试一试{
wait member.roles.add('ROLE_ID');
reply(`${member}现在是mod