如何创建"TempMute"命令?



如何为不和谐创建 TempMute 命令.js它支持《白痴指南》中的命令处理程序。
我知道您需要使用 .addRole() ,但我不知道如何使用计时器创建它。计时器的范围需要为 60 到 15 分钟。

如果您希望在

一段时间后执行操作,则需要使用 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.roles.cache.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.roles.add(mutedRole, `Muted by ${message.author.tag} for ${minutes} minutes. Reason: ${reason}`);
  // Unmute them after x minutes
  setTimeout(() => {
    member.roles.remove(mutedRole, `Temporary mute expired.`);
  }, minutes * 60000); // time in ms
};

这只是一个伪代码,您需要解析参数并获取角色。

最新更新