admin管理员组文章数量:1404927
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!
本文标签: javascriptHow to get a user39s name and discriminator using DiscordJSStack Overflow
版权声明:本文标题:javascript - How to get a user's name and discriminator using Discord.JS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744874873a2629855.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论