How do I get a user's display name and avatar to use in .setAuthor?

^
15 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.
Syjalo
Syjalo2y ago
Currently no way
SuperPEKKA336
SuperPEKKA336OP2y ago
?
GitHub
GitHub2y ago
<:pr_open:852715356622553088> #9512 in discordjs/discord.js by Syjalo opened <t:1683232367:R> (review required) feat: support new username system
monbrey
monbrey2y ago
You can still get a username and avatar, just not what they set as displayName
d.js docs
d.js docs2y ago
property User#username The username of the method User#displayAvatarURL() A link to the user's avatar if they have one. Otherwise a link to their default avatar will be returned.
SuperPEKKA336
SuperPEKKA336OP2y ago
thats what i meant ah ok so interactions.option.displayAvatarURL? const authorURL = interaction.options.displayAvatarURL();
const author = interaction.options.username;
const authorURL = interaction.options.displayAvatarURL();
const author = interaction.options.username;
const authorURL = interaction.options.displayAvatarURL();
would that be right?
monbrey
monbrey2y ago
Not even slightly interaction.user Theyre properties of a user Or if you want them from an option, interaction.options.getUser("option name") and call them on that
SuperPEKKA336
SuperPEKKA336OP2y ago
oh so
const author = interaction.options.getUser(username);
const authorURL= interaction.options.getUser(displayAvatarURL);
const author = interaction.options.getUser(username);
const authorURL= interaction.options.getUser(displayAvatarURL);
monbrey
monbrey2y ago
no monbreyFacepalm you have a slash command where you prompt people to select a user?
SuperPEKKA336
SuperPEKKA336OP2y ago
o *no bros got their own emoji
const {SlashCommandBuilder, Client, PermissionFlagsBits, GatewayIntentBits, EmbedBuilder} = require('discord.js');
const {EMBEDS, ANNOUNCEMENT} = require('../../constants.json');

module.exports =
{
data: new SlashCommandBuilder()
.setName('announcment')
.setDescription('Sends an announcement')
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.addStringOption(option =>
option.setName('title')
.setDescription('Title of the announcement')
.setRequired(true))
.addStringOption(option =>
option.setName('description')
.setDescription('Description of the announcement')
.setRequired(true))
.addChannelOption(option =>
option.setName('channel')
.setDescription('The channel to send the announcement in')
.setRequired(true)),

async execute(interaction)
{
const title = interaction.options.getString('title');
const description = interaction.options.getString('description');
const author = interaction.options.username;
const authorURL = interaction.options.displayAvatarURL();
const channel = interaction.options.getString('channel');

EMBEDS.ANNOUNCEMENT.setTitle(title);
EMBEDS.ANNOUNCEMENT.setDescription(description);
EMBEDS.ANNOUNCEMENT.setAuthor
({
name: author,
iconURL: authorURL
});

await interaction.reply(
{
embeds: [EMBEDS.ANNOUNCEMENT]
});
}
};
const {SlashCommandBuilder, Client, PermissionFlagsBits, GatewayIntentBits, EmbedBuilder} = require('discord.js');
const {EMBEDS, ANNOUNCEMENT} = require('../../constants.json');

module.exports =
{
data: new SlashCommandBuilder()
.setName('announcment')
.setDescription('Sends an announcement')
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.addStringOption(option =>
option.setName('title')
.setDescription('Title of the announcement')
.setRequired(true))
.addStringOption(option =>
option.setName('description')
.setDescription('Description of the announcement')
.setRequired(true))
.addChannelOption(option =>
option.setName('channel')
.setDescription('The channel to send the announcement in')
.setRequired(true)),

async execute(interaction)
{
const title = interaction.options.getString('title');
const description = interaction.options.getString('description');
const author = interaction.options.username;
const authorURL = interaction.options.displayAvatarURL();
const channel = interaction.options.getString('channel');

EMBEDS.ANNOUNCEMENT.setTitle(title);
EMBEDS.ANNOUNCEMENT.setDescription(description);
EMBEDS.ANNOUNCEMENT.setAuthor
({
name: author,
iconURL: authorURL
});

await interaction.reply(
{
embeds: [EMBEDS.ANNOUNCEMENT]
});
}
};
monbrey
monbrey2y ago
okay so use interaction.user like I said It isnt an option
SuperPEKKA336
SuperPEKKA336OP2y ago
so
const author = interaction.user.username;
const authorURL = interaction.user.displayAvatarURL();
const author = interaction.user.username;
const authorURL = interaction.user.displayAvatarURL();
monbrey
monbrey2y ago
Yep
SuperPEKKA336
SuperPEKKA336OP2y ago
k ty
Want results from more Discord servers?
Add your server