Slash Command - Webhook Avatar Not Setting Correctly to User's Avatar

I'm facing an issue where the webhook's avatar is not being set correctly to the user's avatar. Instead, it appears to be blank or set to the default Discord avatar. Expected Behavior: The webhook's avatar should be set to the same avatar as the user who executed the command, making it easy to identify which user initiated the /echo command. Actual Behavior: The webhook's avatar is either set to the default Discord avatar, not matching the user's avatar who executed the command. Here's the part of my code for the /echo command:
module.exports = {
data: new SlashCommandBuilder()
.setName('echo')
.setDescription('Repeat what the user says in the form of a webhook.')
.addStringOption(option =>
option.setName('prompt')
.setDescription('The message content to be echoed')
.setRequired(true)),
async execute(interaction) {
const content = interaction.options.getString('content');

const user = interaction.user;
const { username, avatarURL } = user;

const webhook = await interaction.channel.createWebhook({
name: username,
avatar: avatarURL,
});

await webhook.send(content);

await interaction.reply({ content: 'Success', ephemeral: true });
},
};
module.exports = {
data: new SlashCommandBuilder()
.setName('echo')
.setDescription('Repeat what the user says in the form of a webhook.')
.addStringOption(option =>
option.setName('prompt')
.setDescription('The message content to be echoed')
.setRequired(true)),
async execute(interaction) {
const content = interaction.options.getString('content');

const user = interaction.user;
const { username, avatarURL } = user;

const webhook = await interaction.channel.createWebhook({
name: username,
avatar: avatarURL,
});

await webhook.send(content);

await interaction.reply({ content: 'Success', ephemeral: true });
},
};
Can someone help me understand what I might be doing wrong or suggest an alternative approach to correctly set the webhook's avatar?
3 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. - Issue solved? Press the button!
Trîggered
Trîggered2y ago
user.avatarURL() is a method
macha
machaOP2y ago
hello thank you for your response i changed what u suggested:
const user = interaction.user;
const { username, avatarURL } = user;


const webhook = await interaction.channel.createWebhook({
name: username,
avatar: avatarURL,
});
const user = interaction.user;
const { username, avatarURL } = user;


const webhook = await interaction.channel.createWebhook({
name: username,
avatar: avatarURL,
});
but it still does not give me the avatar i just change avatarURL() to interaction.user.avatarURL() it works now
Want results from more Discord servers?
Add your server