俄罗斯轮盘命令

时间:2018-12-02 04:45:38

标签: bots discord.js

我有一个使用discord.js制作的discord机器人,并且一段时间以来,我一直在尝试向其添加俄语轮盘命令。我希望它有六分之一的机会“开枪”,如果发生这种情况,我希望用户静音30秒。随机化器可以工作,但是对我而言,我无法让漫游器使用户静音。我尝试查看类似的问题,但找不到任何有用的方法。到目前为止,这就是我所拥有的。请注意,我正在自学js atm,因此代码非常垃圾。感谢您的帮助!

var Command = require("../../plugins/Command System/command-system/command");

class russianCommand extends Command {
constructor(client, cs)
{
    super(client, {
        name: "russian",
        memberName: "russian",
        description: "Play a game of Russian Roulette"
    });

    this.cs = cs;
}

async load(msg, args)
{
    const userToMute = msg.author;

    const muteRole = msg.guild.roles.find("name", "Muted");

    const MUTE_TIME = 30 * 1000;

  const answer = [
    ' You\'re safe... For now...',
    ' You\'re safe... For now...',
    ' You\'re safe... For now...',
    ' You\'re safe... For now...',
    ' You\'re safe... For now...',
    ' You died.',
    ]

msg.channel.send(answer[Math.floor(Math.random() * answer.length)]
)

if (answer === ' You died.')
    userToMute.addRole(muteRole);

    setTimeout(() => {
        msg.userToMute.removeRoles(muteRole);
    }, MUTE_TIME);

 }
}

module.exports = russianCommand;

1 个答案:

答案 0 :(得分:0)

第一个userToMute应该是成员而不是用户,不建议使用该角色,您还可以使用removeRole s 而不是removeRole方法,请检查discord.js文档https://discord.js.org/#/docs/main/stable/class/GuildMember?scrollTo=removeRole

let userToMute = msg.member;
let muteRole = msg.guild.roles.find(r => r.name === 'Muted');
let muteTime = 30 * 1000;

let random = Math.random() * 100;
// console.log(random);
if (random < 100 / 6) {
  msg.channel.send(' You died.');
  userToMute.addRole(muteRole);
  setTimeout(() => userToMute.removeRole(muteRole), muteTime);
} else {
  msg.channel.send(' You\'re safe... For now...');
}