【问题标题】:Discord.js - how to ban someone that isn't in the server? || "Error [BAN_RESOLVE_ID]: Couldn't resolve the user ID to ban."Discord.js - 如何禁止不在服务器中的人? || “错误 [BAN_RESOLVE_ID]:无法解析要禁止的用户 ID。”
【发布时间】:2020-09-30 00:11:04
【问题描述】:

我试图让我的禁令命令与不在服务器上的用户一起工作,但我不能,因为唯一的方法(我发现)是使用“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.")
    }

}}

【问题讨论】:

  • mentionedMember 是一个对象。使用mentionedMember.id
  • 嗨!谢谢你的回答。我已经尝试过使用mentionedMember.id,但它不起作用,同样的错误。 @Lioness100

标签: discord discord.js


【解决方案1】:

感谢 Liones100 帮助我。 无论如何,问题很简单。只需在this.client.users.fetch(args[0]) 之前添加一个await

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

【讨论】:

    猜你喜欢
    • 2020-12-21
    • 2020-12-16
    • 1970-01-01
    • 1970-01-01
    • 2021-10-13
    • 2018-06-11
    • 2020-07-21
    • 1970-01-01
    • 2021-06-14
    相关资源
    最近更新 更多