#how can I catch this?

16 messages · Page 1 of 1 (latest)

north lagoon
#

Im working in a avatar command that works with ID and mentions, but when a type something like "!avatar hello" didn't catch nothing and dies :(

calm pilotBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

tacit sierra
#

Then you seem to have a catch somewhere that silently ignores the error… or you didn’t check the console for errors. Because mention will be undefined in your case and thus you can’t access any properties on it

north lagoon
tacit sierra
north lagoon
tacit sierra
#

What does your code look like now?

north lagoon
# tacit sierra What does your code look like now?
////////////////AVATAR////////////////

client.on('messageCreate', async message => {
    const prefix = "tr.";
    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();
    if(message.content.toLowerCase().startsWith(prefix))
      {
          if(command === "av") {

            let mention = message.mentions.users.first().id || (await message.guild.members.fetch(args[0])).id
            let m = mention.username
            if(mention.id == undefined) return;
                const embed = new MessageEmbed()
                  .setColor(`0x2F3136`)
                  .setDescription('aqui esta el avatar 👍')
                  .setImage(await mention.displayAvatarURL({size: 4096, dynamic: true}))
                  .setFooter({text: `Avatar de ${m}`})
                  message.reply({ embeds: [embed] }).catch(() => null)
        }
    }
});
tacit sierra
#

And it will obviously fail again if the fetch returns undefined

north lagoon
#

obviously didnt work

carmine sandal
#

just add a .catch(() => null) after the fetch and then check if mention exists

#

something like:

let mention = message.mentions.users.first() || await message.guild.members.fetch(args[0]).catch(() => null);

if(!mention) return message.channel.send('No user found') 
#

BTW you don't need the await in the displayAvatarURL function