Linked Questions

Popular Questions

delete role from server

Asked by At

So, call me dumb... but I can't get something figured out as to deleting a role from a server permanently. I have role being made for each pair of users that are playing a game in a channel. The role is purely to allow only the 2 players to comment in the channel. I am trying to remove the role once the game is done. The role can be either one of two formats, depending on who was specified as player A and which was player B in a previous separate command.

The below code is giving errors of "(node:19308) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'delete' of null" The console.log(bRole) line is displaying the two users with their usernames not nicknames, so that might be why the find is giving null? The command originally takes mentions. I can't remove all roles or a specific role ID, because the role is generated in a different command with the names of the two players as the role title.

// !endbrawl winner [username] loser [username]

      let messageArray = message.content.split(" ")
      let winner = messageArray[2]
      let winnerUser = message.mentions.users.first();
      let loser = messageArray[4]
      let loserUser = message.mentions.users.last();

    bRole = `${winner.displayName} vs ${loser.displayName}` || `${loser.displayName} vs ${winner.displayName}`
    console.log(bRole)
    guild.roles.find("name", bRole).delete();

I'm just unsure how I'd go about letting the bot find the role so it can be removed. I might just be missing something super simple and easy. Thanks so much for the help in advance.

Related Questions