Search code examples
javascriptnode.jsdiscord.js

How do I make a command give the first mention a role with the ID "973182673306660885"


I have tried the below but i get the error: "msg.mentions.users.first.addRole is not a function"

let BotBanRole = msg.guild.roles.cache.find(r => r.id === "973182673306660885");
  const FMT = msg.mentions.users.first();

if (msg.content.startsWith('$BotBan')) {
    if (FMT === undefined) {
      msg.reply('Did not detect user')
    return; // Do not proceed, there is no user.
  }
  const FM = FMT.username;
  // Do stuff with the username
    msg.mentions.users.first.addRole(BotBanRole);
    msg.reply('Bot Banned ' + FM.tag)
}

Solution

  • You were pretty close, give this a try.

    const BotBanRole = msg.guild.roles.cache.find(r => r.id === "973182673306660885");
    const FMT = msg.mentions.members.first();
    
    if (msg.content.startsWith('$BotBan')) {
        if (!FMT) {
            msg.reply('Did not detect user')
            return;
        } else {
            FMT.roles.add(BotBanRole);
            msg.reply(`Bot Banned ${FMT.user.username}`)
        }
    }