如何为discord.js创建一个TempMute命令,以支持An Idiot's Guide中的命令处理程序。
我了解您需要使用.addRole()
,但是我不知道如何使用计时器创建它。计时器的范围为60到15分钟。
答案 0 :(得分:0)
如果要在一段时间后执行某项操作,则需要使用setTimeout()
。这是一个示例:
// If the command is like: -tempMute <mention> <minutes> [reason]
exports.run = (client, message, [mention, minutes, ...reason]) => {
// You need to parse those arguments, I'll leave that to you
// This is the role you want to assign to the user
let mutedRole = message.guild.find(role => role.name == "Your role's name");
// This is the member you want to mute
let member = message.mentions.members.first();
// Mute the user
member.addRole(mutedRole, `Muted by ${message.author.tag} for ${minutes} minutes. Reason: ${reason}`);
// Unmute them after x minutes
setTimout(() => {
member.removeRole(mutedRole, `Temporary mute expired.`);
}, minutes * 60000);
};
这只是一个伪代码,您需要解析参数并获得角色。