Reputation: 91
So I am coding a bot in discord.js and was working on implementing a welcome DM for when a new user joins the guild. Then when I used ${member.tag}
is returned undefined, what am I doing wrong. I've been trying to figure this out for 10 minutes now and don't want this to escalate into me trying to figure it out for an hour
Code:
client.on('guildMemberAdd', member => {
member.send(`Hello, ${member.tag}`)
});
Upvotes: 1
Views: 1060
Reputation: 5623
There is no tag
property on a GuildMember, so your code is expectedly returning undefined
. It does, however, exist on a User which you can get from the GuildMember with GuildMember#user
.
member.user.tag
is what you're looking for.
NOTE: The Discord.js documentation hyperlinked is for recently released v12. If your Discord.js isn't up to date, switch to the correct version at the top of the page for accurate info.
Upvotes: 2
Reputation: 940
I would give a go to member.displayName
Here is an example that I use
bot.on('guildMemberAdd', member => {
// ADD MEMBER ROLE ON JOIN, this is optional
member.addRole(member.guild.roles.find(role => role.name === "Member"))
const channel = member.guild.channels.find(ch => ch.name === '🛬arrivals')
const welcomeEmbed = new Discord.RichEmbed()
.setTitle(`New member has arrived`)
.setColor(0x8A3F3F)
.setDescription(`Welcome to server, ${member.displayName}!`)
channel.send({ embed: welcomeEmbed })
})
So in your case you can just get rid of the const channel and replace channel.send with member.send
Upvotes: 0