Simon Beya
Simon Beya

Reputation: 11

How do I get someones username AND tag? (Discord.js)

So, I'm trying to make a serverInfo command as you can see below

let embed = new Discord.MessageEmbed()
.setColor("GREEN")
.setTitle("Server Information")
.setDescription(`Server Name: **${message.guild.name}** \n ────────────────── \n Member Count: **${message.guild.memberCount}** \n ────────────────── \n Server ID: **${message.guild.id}** \n ──────────────────`)
.setTimestamp()
.setFooter(`Ran by: ${message.author.username.id}`)
message.channel.send(embed)

For my result, I get "undefiened" anyone know the solution to this? (.setFooter)

Upvotes: 1

Views: 4822

Answers (3)

MrMythical
MrMythical

Reputation: 9041

So, to get the username and tag, just do this:

//say it’s called msg instead of message
var tag = msg.author.tag;
var username = msg.author.id;

//tag would return the user's tag, and as someone else stated in a comment in a previous answer, author returns a user, which itself doesn't have a user property because it is the user object

Also just a quick tip: since it’s server info command, you might want to put some information about the user that’s exclusive to that guild (nickname, roles, permissions), and for that, you can use msg.member which returns a GuildMember, which has a user property, and many more, like member.displayName and member.roles

Upvotes: 0

Anox3D
Anox3D

Reputation: 49

To get the complete tag of a user, you can just use .tag after message.author.

In your code, you're trying to get the username but you put .id after it so this is why you get "undefined".
The ID isn't the numbers with the hashtag, it's the user ID and the tag is the username plus the numbers with the hashtag.

⠀⠀⠀↱ John Doe#3040 ↰
Username⠀⠀⠀⠀ ⠀⠀Numbers
↳⠀⠀⠀⠀⠀⠀⠀⠀Tag⠀⠀⠀⠀⠀⠀⠀ ↲

Upvotes: 0

Leonerrr_
Leonerrr_

Reputation: 104

message.author.tag for get the user with tag (JohnDoe#0000)
message.author.user for get the user
message.author.user.username for get the Username
message.author.user.id for get the ID

Simple (:

Upvotes: 3

Related Questions