javascript - How to get a user's name and discriminator using Discord.JS? - Stack Overflow

Recently I've been coding a discord bot, and I've run into a problem.I've created an ob

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.

Share Improve this question asked Dec 4, 2019 at 23:25 SkyBluSkyBlu 401 gold badge1 silver badge9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

You 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!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744874873a4598487.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信