Discord.js-如何禁止非';t在服务器中?| |&引用;错误[禁止解析ID]:无法';t解析要禁止的用户ID。”;

Discord.js-如何禁止非';t在服务器中?| |&引用;错误[禁止解析ID]:无法';t解析要禁止的用户ID。”;,discord,discord.js,Discord,Discord.js,我试图使我的ban命令与不在服务器上的用户一起工作,但我不能,因为唯一的方法(我发现)是使用“client.fetch.users”,但它抛出了一个错误:“error[ban\u RESOLVE\u ID]:无法将用户ID解析为ban。” 另外,“console.log(referencedMember)”给了我ID(以及用户名等其他信息) const-Command=require('../../Structures/Command'); const{MessageEmbed}=require

我试图使我的ban命令与不在服务器上的用户一起工作,但我不能,因为唯一的方法(我发现)是使用“client.fetch.users”,但它抛出了一个错误:“error[ban\u RESOLVE\u ID]:无法将用户ID解析为ban。”

另外,“console.log(referencedMember)”给了我ID(以及用户名等其他信息)

const-Command=require('../../Structures/Command');
const{MessageEmbed}=require('discord.js')
const config=require(“../../../config.json”)
module.exports=类扩展命令{
构造函数(…参数){
超级(…args{
别名:['forceban','permban'],
描述:“禁止某人。”,
类别:"适度",,
用法:“”
});
}
异步运行(消息,[命令,目标]){
让userId=message.content.substring(message.content.indexOf(“”+1)
常量args=message.content.split(“”).slice(1)
const-sindedMember=message.sindements.members.first()| | this.client.users.fetch(args[0])
const now=新日期();
常量motivo=args.slice(1.join(“”)
如果(!提及成员){
试一试{
如果(!message.guild.members.get(args.slice(0,1.join(“”))抛出新错误('此用户不存在!');
user=message.guild.members.get(args.slice(0,1.join(“”));
user=user.user;
}
捕获(错误){
返回message.channel.send(`${message.author.username},此用户不存在!`);
}
}
如果(referencedMember.id!==message.guild.owner.id){
if(!message.member.hasPermission('BAN_MEMBERS'))返回message.reply(“您没有执行此命令的权限!”)
如果(!message.guild.me.hasPermission('BAN_MEMBERS'))返回message.channel.send(“我不能禁止!给我禁止成员的权限”)
如果(NidedMember.id==message.author.id)返回message.reply(“为什么要禁止自己?”)
试一试{
if(referencedMember.roles.highest.position>=message.member.roles.highest.position){
return message.channel.send(“您不能禁止此成员”)
}}catch(error){console.error(error}
if(!motivo){returnmessage.channel.send(“您应该提供一个原因。”)}
否则{
send(`您在${message.author.username}中被${message.guild.name}禁止,原因:${motivo}`)
wait guild.members.ban(提及成员,{days:7,原因:`禁止者:${message.author.username};原因:${motivo}`})
const LogChannel=wait message.guild.channels.cache.find(channel=>channel.id==config.logModeraçoId)
if(!LogChannel)返回message.channel.send(“禁止成员!”);
var embed=newmessageembed()
.setAuthor(`${message.author.username}-(${message.author.id})`,message.author.displayAvatarURL())
.setThumbnail(referencedMember.user.displayAvatarURL())
.setColor(“红色”)
.setDescription(`
**成员:*${NinteredMember.user.username}-(${NinteredMember.user.id})
**行动:*禁止
**原因:*${motivo | |“未指定”}
**时间:*${now}
`)
LogChannel.send(嵌入)
message.channel.send(`Member banked!请参阅${LogChannel}`中的ban日志)
}
}否则{
return message.channel.send(“您不能禁止此用户!他是服务器所有者。”)
}
}}

谢谢Liones100对我的帮助。 无论如何,问题很简单。只需在
this.client.users.fetch(args[0])
之前放置一个
wait


const-sinderedmember=message.sinderations.members.first()| |等待这个.client.users.fetch(args[0])
sinderedmember
是一个对象。使用
sinderedmember.id
您好!谢谢您的回答。我已经尝试过使用
sinderedmember.id
了,但它不起作用,同样的错误。@Lioness100
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.")
    }

}}