如何禁止和踢公会成员

时间:2018-07-30 09:19:20

标签: discord.js

好吧,我遵循了“源代码”“ discord.js”教程(甚至从GitHub复制粘贴了他的代码),但是他显示的ban和kick命令不起作用,我认为它们被最新版本破坏了更新。它会将嵌入内容发送到事件频道,但实际上并没有禁止播放器。另外,如果您对我有任何更改建议,请提出建议!

if (cmd === `${prefix}ban`) {
  let bUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
  if (!bUser) return message.channel.send("Can't find user!");
  let bReason = args.join(" ").slice(22);
  if (!message.member.hasPermission("MANAGE_MEMBERS")) return message.channel.send("No can do pal!");
  if (bUser.hasPermission("MANAGE_MESSAGES")) return message.channel.send("That person can't be banned!");

  let banEmbed = new Discord.RichEmbed()
    .setDescription("Ban Management")
    .setColor("#bc0000")
    .addField("Banned User", `${bUser} with ID ${bUser.id}`)
    .addField("Banned By", `<@${message.author.id}> with ID ${message.author.id}`)
    .addField("Banned In", message.channel)
    .addField("Time", message.createdAt)
    .addField("Reason", bReason);

  let incidentchannel = message.guild.channels.find(`name`, "incidents");
  if (!incidentchannel) return message.channel.send("Can't find incidents channel.");

  message.guild.member(bUser).ban(bReason);
  message.delete().catch(O_o => {});
  incidentchannel.send(banEmbed);

  return;
}

3 个答案:

答案 0 :(得分:1)

message.guild.member(bUser).ban(bReason);

这不会禁止该会员。该邮件具有member属性,因此您不需要使用message.guild.member,就可以轻松使用message.member

所以它应该像这样:

if (cmd === `${prefix}ban`) {
  let bUser = message.guild.member(message.mentions.members.first() || message.guild.members.get(args[0]));
  if (!bUser) return message.channel.send("Can't find user!");
  let bReason = args.join(" ").slice(22);
  if (!message.member.hasPermission("MANAGE_MEMBERS")) return message.channel.send("No can do pal!");
  if (bUser.hasPermission("MANAGE_MESSAGES")) return message.channel.send("That person can't be banned!");

  let banEmbed = new Discord.RichEmbed()
    .setDescription("Ban Management")
    .setColor("#bc0000")
    .addField("Banned User", `${bUser.user.tag} with ID ${bUser.id}`)
    .addField("Banned By", `<@${message.author.id}> with ID ${message.author.id}`)
    .addField("Banned In", message.channel.name)
    .addField("Time", message.createdAt)
    .addField("Reason", bReason);

  let incidentchannel = message.guild.channels.find(`name`, "incidents");
  if (!incidentchannel) return message.channel.send("Can't find incidents channel.");

  message.guild.member(bUser).ban({
    reason: bReason
  });
  message.delete();
  incidentchannel.send({
    embed: banEmbed
  });

  return;
}

我做了很多改变,因为很多东西已经过时了,无法正常工作。可能是我没有看到一个或另一个错误。

让我知道它是否有效! :)

最好的问候, Monkeyyy11

答案 1 :(得分:0)

如果您使用discord.js v12或更高版本,则RichEmbed现在已弃用。而是使用MessageEmbed

答案 2 :(得分:0)

这似乎非常复杂,我希望我的命令可以使事情变得简单一些!

bot.on('message', message => {
    const arguments = message.content.slice(prefix.length).trim().split(/ +/g);
    const commandName = arguments.shift().toLowerCase();
if (message.content.startsWith(prefix) && commandName == "kick") {
    if(!message.member.hasPermission("KICK_MEMBERS")) return message.channel.send("Permissions invalid");
    const userKick = message.mentions.users.first();

    if (userKick) {
        var member = message.guild.member(userKick);

        if (member) {
            member.kick({
                reason: `This person was kicked using a bot's moderation system. We are so sorry if this caused problems.`
    }).then(() => {
        message.reply(`A user been kicked.`) 
    })
} else {
    message.reply(`User not found`);
}
    } else {
        message.reply(`Please enter a name`)
    }}})


    bot.on('message', message => {
        const arguments = message.content.slice(prefix.length).trim().split(/ +/g);
        const commandName = arguments.shift().toLowerCase();
    if (message.content.startsWith(prefix) && commandName == "ban") {
        if(!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send("Permissions invalid");
        const userBan = message.mentions.users.first();
    
        if (userBan) {
            var member = message.guild.member(userBan);
    
            if (member) {
                member.ban({
                    reason: `This person was banned using a bot's moderation system. We are so sorry if this caused problems.`
        }).then(() => {
            message.reply(`a user has been banned!`) 
        })
    } else {
        message.reply(`User not found`);
    }
        } else {
            message.reply(`Please enter a name`)
        }}})