problem displaying avatar per server

Hi guys, Im trying to make an Avatar command that Displays both avatar per server, this means 1- default avatar 2-Server Avatar (nitro) I already made it works, but doesn't seems to work with mentions or ID's mentions, what im doing wrong? here an example:
8 Replies
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
TRKako
TRKakoOPā€¢2y ago
also, here's the code:
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" || command === "avatar" || command === "foto"){

try {

let usuario;
if (message.mentions.users.first()) {
usuario = message.mentions.users.first().id;
} else if (args[0]) {
usuario = args[0];
} else {
usuario = message.author.id;
}

try {

const user = await client.users.fetch(usuario)


const embed = new Discord.MessageEmbed()
.setTitle('Avatar šŸ‘')
.setDescription(`Avatar: ` + '**`' + user.tag + '`**')
.setColor(`0x2F3136`)
.setImage(user.displayAvatarURL({format: "png", size: 4096, dynamic: true}))

const embed1 = new Discord.MessageEmbed()
.setTitle('Avatar šŸ‘')
.setDescription(`Avatar: ` + '**`' + message.member.displayName + '`**')
.setColor(`0x2F3136`)
.setImage(message.member.displayAvatarURL({format: "png", size: 4096, dynamic: true}))

const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setLabel('> open avatar in browser <')
.setURL(user.displayAvatarURL({format: "png", size: 4096, dynamic: true}))
.setStyle('LINK'),
);

const row1 = new MessageActionRow()
.addComponents(
new MessageButton()
.setLabel('> open avatar in browser <')
.setURL(message.member.displayAvatarURL({format: "png", size: 4096, dynamic: true}))
.setStyle('LINK'),
);

const rowo = new MessageActionRow()
.addComponents(
new MessageButton()
.setLabel('> Default Avatar <')
.setCustomId('row-ROWO')
.setStyle('PRIMARY')
)
const filter = (interaction) => {
if (!interaction.isButton) return
if (interaction.customId.includes('-ROWO'));

interaction.update({ embeds: [embed], components: [row]}).catch(() => null)
}
const collector = message.channel.createMessageComponentCollector({
filter,
max: 1,
});

/////////////

message.reply({ embeds: [embed1], components: [rowo, row1]}).catch(() => null)

/////////////
} catch {
message.react('āŒ')
const errorembed = new Discord.MessageEmbed()
.setColor('RED')
.setDescription('> Fatal error showing avatar:\n `' + usuario + '`' + ` It's not a valid ID`)
message.reply({embeds: [errorembed]}).catch(() => null)
.then(message => {
setTimeout(() => message.delete(), 10000)
}).catch(() => null)
}
} catch (error) {
null
}
}
}
});
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" || command === "avatar" || command === "foto"){

try {

let usuario;
if (message.mentions.users.first()) {
usuario = message.mentions.users.first().id;
} else if (args[0]) {
usuario = args[0];
} else {
usuario = message.author.id;
}

try {

const user = await client.users.fetch(usuario)


const embed = new Discord.MessageEmbed()
.setTitle('Avatar šŸ‘')
.setDescription(`Avatar: ` + '**`' + user.tag + '`**')
.setColor(`0x2F3136`)
.setImage(user.displayAvatarURL({format: "png", size: 4096, dynamic: true}))

const embed1 = new Discord.MessageEmbed()
.setTitle('Avatar šŸ‘')
.setDescription(`Avatar: ` + '**`' + message.member.displayName + '`**')
.setColor(`0x2F3136`)
.setImage(message.member.displayAvatarURL({format: "png", size: 4096, dynamic: true}))

const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setLabel('> open avatar in browser <')
.setURL(user.displayAvatarURL({format: "png", size: 4096, dynamic: true}))
.setStyle('LINK'),
);

const row1 = new MessageActionRow()
.addComponents(
new MessageButton()
.setLabel('> open avatar in browser <')
.setURL(message.member.displayAvatarURL({format: "png", size: 4096, dynamic: true}))
.setStyle('LINK'),
);

const rowo = new MessageActionRow()
.addComponents(
new MessageButton()
.setLabel('> Default Avatar <')
.setCustomId('row-ROWO')
.setStyle('PRIMARY')
)
const filter = (interaction) => {
if (!interaction.isButton) return
if (interaction.customId.includes('-ROWO'));

interaction.update({ embeds: [embed], components: [row]}).catch(() => null)
}
const collector = message.channel.createMessageComponentCollector({
filter,
max: 1,
});

/////////////

message.reply({ embeds: [embed1], components: [rowo, row1]}).catch(() => null)

/////////////
} catch {
message.react('āŒ')
const errorembed = new Discord.MessageEmbed()
.setColor('RED')
.setDescription('> Fatal error showing avatar:\n `' + usuario + '`' + ` It's not a valid ID`)
message.reply({embeds: [errorembed]}).catch(() => null)
.then(message => {
setTimeout(() => message.delete(), 10000)
}).catch(() => null)
}
} catch (error) {
null
}
}
}
});
duck
duckā€¢2y ago
it looks like your initial reply sends embed1, which is defined with message.member's info rather than user beyond that, consider logging message.mentions.users.first() or usario I'd also consider handling collected component interactions on collect rather than in the filter
d.js docs
d.js docsā€¢2y ago
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops. ā€¢ Once you do, log relevant values and if-conditions ā€¢ More sophisticated debugging methods are breakpoints and runtime inspections: learn more
TRKako
TRKakoOPā€¢2y ago
thx, you're right, I logged: -message.member.id & message.member.user.tag -usuario -message.mentions.users.first() and message.member.id & message.member.user.tag are displaying my ID, while usuario and message.mentions.users.first() are displaying the mentioned user poto
TRKako
TRKakoOPā€¢2y ago
Help, I don't know how to get server avatar without member.user abduzcanabduzcanabduzcanabduzcanabduzcanabduzcanabduzcanabduzcanabduzcan
d.js docs
d.js docsā€¢2y ago
method GuildMember#displayAvatarURL() A link to the member's guild avatar if they have one. Otherwise, a link to their User#displayAvatarURL() will be returned.
TRKako
TRKakoOPā€¢2y ago
But that doesn't help in any way <a:TCMN_jaderr:812446303144640543>
Want results from more Discord servers?
Add your server