Avatar error

TypeError: user.displayAvatarURL is not a function at Object.execute (C:\Users\csc21\OneDrive\Desktop\soapjs\src\components\buttons\userinfo.js:20:27) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (C:\Users\csc21\OneDrive\Desktop\soapjs\src\events\client\interactionCreate.js:30:9)
10 Replies
d.js toolkit
d.js toolkit2y ago
• 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.
Soap
SoapOP2y ago
code:
const {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
} = require("discord.js");

module.exports = {
data: {
name: `userinfo`,
},
async execute(interaction, client) {
const message = await interaction.deferReply({
fetchReply: true,
});
let custom = interaction.customId;
let split = custom.split("-");

let user = split[1] || interaction.member;
let userAvatar = user.displayAvatarURL({ size: 1024 });

const username = user.username;
const Discriminator = user.discriminator;
const id = user.id;

const newMessage = ``;
const embed = new EmbedBuilder()
.setTitle(`${username}'s user info`)
.setURL(`https://discordapp.com/users/${id}`)
.setImage(`${userAvatar}`)
.setColor("Random")

.addFields(
{ name: `Username`, value: `${username}`, inline: true },
{ name: `Tag`, value: `${Discriminator}`, inline: true },
{ name: `User ID`, value: `${id}`, inline: true },
{ name: `Profile URL`, value: `[Here!](${userAvatar})`, inline: true }
);

await interaction.editReply({
embeds: [embed],
});
},
};
const {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
} = require("discord.js");

module.exports = {
data: {
name: `userinfo`,
},
async execute(interaction, client) {
const message = await interaction.deferReply({
fetchReply: true,
});
let custom = interaction.customId;
let split = custom.split("-");

let user = split[1] || interaction.member;
let userAvatar = user.displayAvatarURL({ size: 1024 });

const username = user.username;
const Discriminator = user.discriminator;
const id = user.id;

const newMessage = ``;
const embed = new EmbedBuilder()
.setTitle(`${username}'s user info`)
.setURL(`https://discordapp.com/users/${id}`)
.setImage(`${userAvatar}`)
.setColor("Random")

.addFields(
{ name: `Username`, value: `${username}`, inline: true },
{ name: `Tag`, value: `${Discriminator}`, inline: true },
{ name: `User ID`, value: `${id}`, inline: true },
{ name: `Profile URL`, value: `[Here!](${userAvatar})`, inline: true }
);

await interaction.editReply({
embeds: [embed],
});
},
};
Idris
Idris2y ago
user is a string and a string does not have this method
Soap
SoapOP2y ago
so what do i need to change
Idris
Idris2y ago
fetch the user with its id
Soap
SoapOP2y ago
i believe it does split[1] gives a userid
Idris
Idris2y ago
and an ID is a string ^
Soap
SoapOP2y ago
wdum
Idris
Idris2y ago
- let user = split[1] || interaction.member;
+ let user = split[1] ? await interaction.client.users.fetch(split[1]) : interaction.user;
- let user = split[1] || interaction.member;
+ let user = split[1] ? await interaction.client.users.fetch(split[1]) : interaction.user;
Soap
SoapOP2y ago
tyy
Want results from more Discord servers?
Add your server