What is the bot variant for message.bot.username?

Viewed 164

I was upgrading a ban command for my Discord bot (Discord.js). This is my command now (without some unnecessary code):

  const target = message.mentions.users.first();
  if (target) {
    const memberTarget = message.guild.members.cache.get(target.id);
    memberTarget.ban();
    message.channel.send(
      `<@${memberTarget.user.id}> got 360 no-scoped by ${message.bot.username}`
    );
  } else {
    message.channel.send(process.env.MSGERR);
  }
},

The problem here is that message.bot.username is not working. I have multiple bots, so I would like the bot username as a variable. When I tried message.author.username, it does work.

So my question is what is the bot variant of the message.author.username?

2 Answers

You'll need to get the User object of the client, then access the username. You can get the client from message.client

const { username } = message.client.user;

// Same as 
const username = message.client.user.username;

If you need to get your bot username on discord.js v13 you can use: client.user.tag instead of message.bot.username

Related