在Discord.JS中禁止公会会员

时间:2020-08-09 13:23:18

标签: javascript node.js discord discord.js

client.on('message', message => {
    if (!message.guild) return;

    if (message.content.startsWith('-ban')) {
        const user = message.mentions.users.first();

        if (user) {
            const member = message.guild.member(user);

            if (member) {
                .ban({
                    reason: 'They were bad!',
                })
                .then(() => {
                    message.reply(`Sikeresen kitiltva a szerverről!`);
                })
                .catch(err => {
                    message.reply('Nem tudtam kitiltani a felhasználót');
                    console.error(err);
                });
            } else {
                message.reply("Ez a felhasználó nem tartózkodik a szerveren!!");
            }
        } else {
            message.reply("Meg kell nevezned egy személyt!!");
        }
    }
});

我正在尝试使用此代码禁止某人,但是我不能这样做,因为在“ ban({”之前,我有一个。!但是,如果删除它,我就不能禁止。它在那里,我无法运行我的Discord Bot:/

1 个答案:

答案 0 :(得分:0)

client.on("message", message => {
    if (!message.guild) return false;

    if (message.content.toLowerCase().startsWith("-ban")) {
        if (!message.member.hasPermission("BAN_MEMBERS")) return message.reply("You cannot ban members.");
        const member = message.mentions.members.first();
        if (!member) return message.channel.send("Provide a user to ban.");

        member.ban({reason: "They were bad!"}).then(() => {
            message.reply(`${member.user.tag} was banned.`);
        }).catch(e => {message.reply(`Couldn't ban ${member.user.tag}.`)});
    };
});