我一直在试图找到一种方法,将带有标记用户的!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`);
}
})
答案 0 :(得分:0)
对于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);