Using # in text for discord-bot

So, I want my code to check if a variable is the same as a specific discord user.
The code I’m using is

if (member == Examplemember#1234) {
var oldVar = newVar
} 

If anyone could help me fix the issue that the hashtag is causing, that would be very nice.

Thanks you for your help in advance

If you need to check a unique user, should be better to use id instead username and discriminator

Something like this

if(member.user.id == '12345678987654321') {
  // stuff here
}

But if you need for something specific discriminator and username you can do something like this.

let fullname = `${member.user.username}#${member.user.discriminator}`

if(fullname == 'ExampleUsername#1234'){
  // stuff here
}

fyi the member in there is a custom variable

I’m trying to check if the person @mentions the bot.

I’ve made it so the @mention is turned into a variable that I easily can use

In that case you should check if there is a mention to the user of your bot. You do not need to turn it into a variable :slight_smile:

if(message.isMentioned(Client.user)){
	// the bot was @mention
} else {
	// the bot wasn't @mention
}
1 Like

I get an error saying that “Message.ismentioned is not a function”

Can you give us your project name so we can take a closer look? Or can you share more of your code here?

nvm I had just misspelled it. But now it just won’t send a response.

More code is here:

var member = message.mentions.members.first();

 if (message.isMentioned(client.user)) {
      var punch = punchdodge
      var specialcase = 2

if (specialcase == 2) {
        message.channel.send("Dodged it! You can't tell the person you'll hit that you'll hit them, " + member2.displayName + "!", {
          files: punch

Ok, it was just me being stupid again. Thanks for the help, mate!

No problem, glad you figured out

You were right all along, this one goes to you