最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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!

发布评论

评论列表(0)

  1. 暂无评论