Search code examples
javascriptnode.jsdiscord.js

How to fix a bug in the catch function Discord.js


I am making a code to ban, and I encountered such a problem that the bot does not stop playing the code

code

message.guild.members.ban(args[0]).catch(err => {
            if (err.code === 10013) return message.channel.send({ embeds: [new MessageEmbed().setTitle('Oh no!').setDescription('No user').setColor('ff3333')]})
            if (err.code === 50035) return message.channel.send({ embeds: [new MessageEmbed().setTitle('Oh no!').setDescription('No user').setColor('ff3333')]})
        })
         message.reply({ embeds: [new MessageEmbed().setTitle('Ban').setDescription(`User - <@${args[0]}> ban\nMod - ${message.author}\nReson - ${args.slice(1).join(' ')}`)] })

( Decided )


Solution

  • message.guild.members.ban(args[0]).then(banu => {
    message.reply({ embeds: [new MessageEmbed().setTitle('Ban').setDescription(`User - ${banu} ban\Mod - ${message.author}\nReson - ${args.slice(1).join(' ')}`)] })
    }).catch(err => {
                if (err.code === 10013) return message.channel.send({ embeds: [new MessageEmbed().setTitle('Oh no!').setDescription('No user').setColor('ff3333')]})
                if (err.code === 50035) return message.channel.send({ embeds: [new MessageEmbed().setTitle('Oh no!').setDescription('No user').setColor('ff3333')]})
            })```