Recently I've been coding a discord bot, and I've run into a problem.
I've created an object array which stores a user and a string when they run l!start
.
I'm not sure how to get a user's name and discriminator using discord.js.
var usersStarters = [
];
// other code
usersStarters.push({
<member>.user.username + <member>.user.discriminator: "string"
});
Here's my code at the moment. <member>.user.username
and <member>.user.discriminator
don't work, but I'm not sure what else to put in.
Recently I've been coding a discord bot, and I've run into a problem.
I've created an object array which stores a user and a string when they run l!start
.
I'm not sure how to get a user's name and discriminator using discord.js.
var usersStarters = [
];
// other code
usersStarters.push({
<member>.user.username + <member>.user.discriminator: "string"
});
Here's my code at the moment. <member>.user.username
and <member>.user.discriminator
don't work, but I'm not sure what else to put in.
1 Answer
Reset to default 3You can grab the author's username and discriminator bined by just using this code.
message.author.tag
I will show you this in a context of creating a log on the console.
console.log('[', chalk.hex('#5cc9ed')('INFO'), '] ', `Failed purge mand in server ${message.guild.id} by user ${message.author.tag}`);
As you can see, console.log just prints into the console screen, I then have a "[" printed followed by a color selector from Chalk (I remend you use Chalk with NPM) which prints "INFO" followed by another "]".
Next I have used tildes (these characters: ``) to allow code in a string, you can add code in a string with ${} and it will grab that code and put it into the string. Saves a lot of time.
Then it will start to print out the log, in this case it is for purge mand, it will state the server ID with ${message.guild.id} and then you can get the username with discriminator by using ${message.author.tag}.
If you JUST want the discriminator, you can use message.author.discriminator or just username for the username, and if you just want the ID of the user, you can do message.author.id.
Good luck on development!