俄罗斯轮盘命令
Russian Roulette command
我有一个用 discord.js 制作的 discord 机器人,一段时间以来我一直在尝试向它添加俄罗斯轮盘命令。我希望它有六分之一的机会开枪 "going off",如果发生这种情况,我希望用户静音 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;
首先 userToMute
应该是成员而不是用户,不推荐使用查找角色的方式,您还使用 removeRoles 而不是 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...');
}
我有一个用 discord.js 制作的 discord 机器人,一段时间以来我一直在尝试向它添加俄罗斯轮盘命令。我希望它有六分之一的机会开枪 "going off",如果发生这种情况,我希望用户静音 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;
首先 userToMute
应该是成员而不是用户,不推荐使用查找角色的方式,您还使用 removeRoles 而不是 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...');
}