Discord.js命令启动和禁止

时间:2020-06-30 03:42:14

标签: javascript discord discord.js

Discord.js 12.2.0

有人可以告诉我有关踢和禁令的信息吗?

if(message.content === prefix+"ban"){

}


if(message.content === prefix+"kick"){

}

3 个答案:

答案 0 :(得分:1)

要禁止会员,请执行以下操作:

if(message.content === prefix + "ban") {
   message.members.mentions.first().ban();
}

您使用以下方法踢成员:

if(message.content === prefix + "ban") {
   message.members.mentions.first().kick();
}

但是请注意,任何人都可以使用这两个命令,您必须添加权限过滤器以防止这种情况。

See the docs guide for the ppermissions

答案 1 :(得分:0)

您可以通过以下操作禁止成员:

<GuildMember>.ban() //to ban
<GuildMember>.kick() //to kick

其中<GuildMember>代表Discord上的公会成员。

您可以通过执行以下操作来获得<GuildMember>

message.mentions.members.first();

您可以参考how to kick a user以获得更多信息。

答案 2 :(得分:0)

这是我用于禁止和踢出命令的内容。 这是我的禁令命令:

TASK [View the Difference Against Existing and Desired DHCP Configs]
TASK [Delete Non-Site Standards DHCP Config]

这是我的踢球命令:

if (message.content.startsWith("s!ban")) {
    if (!message.guild.member(message.author).hasPermission("BAN_MEMBERS")) {
            return message.channel.send('You do not have the permission to ban users!');
        }
    if (!message.guild.member(client.user).hasPermission("BAN_MEMBERS")) {
            return message.channel.send("I don't have the permission to ban users!");
    }
    if (message.mentions.users.size === 0) {
        return message.channel.send("You need to ping a user or the user can't be found!");
    }
    var member = message.mention.members.first();
    member
        .ban()
        .then(member => {
            guild.members.ban(id);
            message.channel.send("*It's a plane* :airplane:, *no its a bird* :bird:, *wait no its just* **" + member.displayName + "** *getting banned :hammer:*");
        })
        .catch(() => {
            message.channel.send("Sorry, you can't ban this member");
        });
    }