Accessing .addUserOption Pfp and bot pfp

I'm currently working alongside the online guide, and I've come across an issue I couldn't find. The current project structure contains a folder "commands", in which each file represents a command. I'm working on one file and try to obtain a target user's profile picture, as well as the bot's profile picture to display in an Embed. While interaction.user.displayAvatarURL() works as expected, I can't seem to figure out how to get the same URL from interaction.options.getUser("user"). Additionally, I don't know where I can locate the bot's profile picture to begin with. I assumed it's in the client object, but how do I access that from a separate file? Thanks in advance.
6 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Luca | LeCarbonator
Node is v16.14.2 if necessary
조아오
조아오3y ago
Client.user.displayAvatarURL() And make sure the option name matches the name you are querying and that if the option isn't required you need to handle the user not existing
Luca | LeCarbonator
Hmm and how do I pass client to the file? Do I simply pass it as parameter in the execute method? This is where the command is called in index.js
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction); // execute(interaction, client) instead?
} catch (error) {
console.error(error);
await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true,
});
}
});
client.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
try {
await command.execute(interaction); // execute(interaction, client) instead?
} catch (error) {
console.error(error);
await interaction.reply({
content: "There was an error while executing this command!",
ephemeral: true,
});
}
});
wow, that is quite unreadable in this small window command.execute(interaction) turning into command.execute(interaction, client), is that how you access client from the command file?
조아오
조아오3y ago
You can get client from any structure
Luca | LeCarbonator
oh, alright. I have to test that then well, that summed up all my questions, thanks for your help. I'll close the post now
Want results from more Discord servers?
Add your server