const Discord = require("discord.js"),
bot = new Discord.Client();
let pre = "?"
bot.on("message", async msg => {
var msgArray = msg.content.split(" ");
var args = msgArray.slice(1);
var prisonerRole = msg.guild.roles.find("name", "Prisoner");
let command = msgArray[0];
if (command == `${pre}roll`) {
if (!msg.member.roles.has(prisonerRole.id)) {
roll = Math.floor(Math.random()*6)+1;
msg.reply(`You rolled a ${roll}`)
} else {
msg.reply(`HaHa NOOB, you're in prison you don't get priveleges!`)
}
}
if (command == `${pre}kick`) {
var leaderRole = msg.guild.roles.find("name", "LEADER");
var co_leaderRole = msg.guild.roles.find("name", "CO-LEADER");
if (msg.member.roles.has(leaderRole.id) ||
msg.member.roles.has(co_leaderRole.id)) {
var kickUser = msg.guild.member(msg.mentions.users.first());
var kickReason = args.join(" ").slice(22);
msg.guild.member(kickUser).kick();
msg.channel.send(`${msg.author} has kicked ${kickUser}\nReason: ${kickReason}`);
} else {
return msg.reply("Ya pleb, you can't kick people!");
}
}
})
bot.login("token").then(function() {
console.log('Good!')
}, function(err) {
console.log('Still good, as long as the process now exits.')
bot.destroy()
})
除了实际踢人之外,一切都有效。消息发疯了,它不会踢人。例如,当我输入?kick @BobNuggets#4576 inactive
时,它会显示
@rishabhase has kicked @BobNuggets
Reason: inactive
但这实际上并没有踢用户,这很奇怪,您能帮我吗?
答案 0 :(得分:0)
更改
msg.guild.member(kickUser).kick();
到
kickUser.kick();
另外,请确保漫游器在层次结构中得到提升
答案 1 :(得分:0)
使用kickUser.kick();
我建议使用命令处理程序来整理代码。您不希望将所有命令放在一个.js文件中。
答案 2 :(得分:0)
对Ban命令本身尝试类似的操作。我将其用于我的机器人:
client.on("message", (message) => {
if (message.content.startsWith("!ban")) {
if(!message.member.roles.find("name", "Role that can use this bot"))
return;
// Easy way to get member object though mentions.
var member= message.mentions.members.first();
// ban
member.ban().then((member) => {
// Successmessage
message.channel.send(":wave: " + member.displayName + " has been successfully banned :point_right: ");
}).catch(() => {
// Failmessage
message.channel.send("Access Denied");
});
}
});
这应该起作用,设置您要使用的角色(cAsE sEnSiTiVe),并将!ban更改为您想使用的任何内容。如果您将此踢中的所有“禁止”更改为踢踢,则将具有相同的效果。如果这样做对您有帮助,请将其标记为答案,以便其他人可以找到它,如果没有找到,请继续寻找:)