使用提及向用户添加/删除角色



我一直在尝试找到一种方法,将!timeout命令与标记用户一起使用,以向他们添加timeout角色,反之亦然,使用!timeoutcomplete命令。

const Discord = require('discord.js');
const client = new Discord.Client();
const token = '<token id>';
const prefix = '!';
client.on('message', message => {
var role = message.guild.roles.cache.get('699778380937166878');
const taggedUser = message.mentions.members.first();

if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(' ');
const command = args.shift().toLowerCase();
if (!message.mentions.users.size) {
return message.channel.send('i dont know who you want me to put in timeout');
}
if (command === 'timeout') {
message.channel.send(`${taggedUser} has been put in timeout`);
}
if (command === 'timeoutcomplete') {
message.channel.send(`${taggedUser} has completed their timeout`);
}
})

对于timeout,您可以使用roles.add()来完成此操作,如下所示:

if (!taggedUser) return message.reply('you need to mention a user');
taggedUser.roles.add(role);

对于timeoutcomplete,您可以使用roles.remove()来完成此操作,如下所示:

if (!taggedUser) return message.reply('you need to mention a user');
taggedUser.roles.remove(role);

最新更新