I’m trying to get a user Discord username by a Discord bot using Discord.js V14.
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Bot is ready');
});
client.on('message', message => {
if (message.content = '!username') {
const username = message.author.username;
message.channel.send(`Your username is: ${username}`);
}
});
client.login('your-bot-token');
New contributor
Perseus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.