Discord.js-如何禁止不在服务器中的人? || “错误[BAN_RESOLVE_ID]:无法解析要禁止的用户ID。”

时间:2020-09-28 12:45:32

标签: discord discord.js

我试图使ban命令与不在服务器上的用户一起使用,但是我做不到,因为(我发现的)唯一方法是使用“ client.fetch.users”,但是它会引发错误:“错误[BAN_RESOLVE_ID]:无法解析要禁止的用户ID。”

此外,“ console.log(提及成员)”为我提供了ID(以及用户名等其他信息)。

const Command = require('../../Structures/Command');
const { MessageEmbed } = require('discord.js')
const config = require('../../../config.json')

module.exports = class extends Command {

    constructor(...args) {
        super(...args, {
            aliases: ['forceban', 'permban'],
            description: 'bans someone.',
            category: 'moderation',
            usage:'<@user>  <reasom>'
        });
    }
    async run(message, [command, target]) {

        let userId = message.content.substring(message.content.indexOf(" ") + 1)
        const args = message.content.split(' ').slice(1)
        const mentionedMember = message.mentions.members.first() || this.client.users.fetch(args[0])
        const now = new Date();
        const motivo = args.slice(1).join(" ")
        if (!mentionedMember){
            try{
                if (!message.guild.members.get(args.slice(0, 1).join(' '))) throw new Error('This user doesn't exists!');
                user = message.guild.members.get(args.slice(0, 1).join(' '));
                user = user.user;
            }
            catch (error) {
                return message.channel.send(`${message.author.username}, this user doesn't exists!`);
                }
        }
        if(mentionedMember.id !==message.guild.owner.id){ 
        


        if (!message.member.hasPermission('BAN_MEMBERS')) return message.reply("You don't have permissions to execute this command!")
        if (!message.guild.me.hasPermission('BAN_MEMBERS')) return message.channel.send("I can't ban! Give me the permission to ban members.")
        if (mentionedMember.id === message.author.id) return message.reply("Why would you ban yourself?")
        try{
        if (mentionedMember.roles.highest.position >= message.member.roles.highest.position){
            return message.channel.send("You can't ban this member.")
        }}catch(error){console.error(error}
            if (!motivo){return message.channel.send("You should provide a reason.")}
        else{
        
            
            mentionedMember.send(`You was banned in ${message.guild.name} by ${message.author.username}, reason: ${motivo}`)
            await guild.members.ban(mentionedMember, {days: 7, reason: `banned by: ${message.author.username}; reason: ${motivo}`})
            const LogChannel = await message.guild.channels.cache.find(channel=>channel.id == config.logModeraçãoId)
            if(!LogChannel) return message.channel.send("Member banned!");
            
            var embed = new MessageEmbed()
            .setAuthor(`${message.author.username} - (${message.author.id})`, message.author.displayAvatarURL())
            .setThumbnail(mentionedMember.user.displayAvatarURL())
            .setColor('RED')
            .setDescription(`
            **Member:** ${mentionedMember.user.username} - (${mentionedMember.user.id})
            **Action:** ban
            **Reason:** ${motivo || "not specified"}
            **Time:** ${now}
            `)
            LogChannel.send(embed)
            message.channel.send(`Member banned! See the ban log in ${LogChannel}`)
        }
     
     }else{
        return message.channel.send ("You can't ban this user! He is the server owner.")
    }

}}

1 个答案:

答案 0 :(得分:0)

感谢Liones100对我的帮助。 无论如何,问题很简单。只需将await放在this.client.users.fetch(args[0])之前即可。

const mentionedMember = message.mentions.members.first() || await this.client.users.fetch(args[0])