1

Trying to make an on_message event where multiple roles can use the command. It works when I put one of the individual roles like FO, GM, HC, AC but when I put all of them in there as "staffroles" it doesn't respond.

if "sign" in message.content:
      signer=message.author
      signee=message.mentions[0].mention
      signeeid=message.mentions[0].id
      server=bot.get_guild(782690561135083551)
      teamsidslist=[782730424093769748, 788549127499153459, 787889904465215519, 786747382905176074, 783495172117102654, 788872681184952360, 782997813947531315, 782750341850333245, 800268209420369951, 788579996184477697, 788902115849666621, 799668339881672734, 788587247951675422, 783151342293745705]
      teamnames=['Detroit Lions', 'Los Angeles Rams', 'Seattle Seahawks', 'Cleveland Browns', 'Pittsburgh Steelers', 'Buffalo Bills', 'Atlanta Falcons', 'San Francisco 49ers', 'Arizona Cardinals', 'Green Bay Packers', 'Indianapolis Colts', 'New Orleans Saints', 'Tennessee Titans', 'Jacksonville Jaguars']
      teamemojis=['Detroit_Lions', 'Los_Angeles_Rams', 'Seattle_Seahawks', 'Cleveland_Browns', 'Pittsburgh_Steelers', 'Buffalo_Bills', 'Atlanta_Falcons', 'Green_Bay_Packers', 'Indianapolis_Colts', 'New_Orleans_Saints', 'Tennessee_Titans', 'Jacksonville_Jaguars']
      FO = discord.utils.get(message.author.guild.roles, id=782730552037081128)
      GM = discord.utils.get(message.author.guild.roles, id=802169554880692275)
      HC = discord.utils.get(message.author.guild.roles, id=802169838205796352)
      AC = discord.utils.get(message.author.guild.roles, id=802169983088984094)
      staffroles = [FO, GM, HC, AC]
      FA = discord.utils.get(message.author.guild.roles, id=782711892577615883)
      Suspended = discord.utils.get(message.author.guild.roles, id=804363507842940948)
      roster=[]
      agency=[]
      teams=[]
      for rolesids in message.author.roles:
        if rolesids.id in teamsidslist:
          teams.append(rolesids.id)
          step2=str(teams)
          step3=step2.replace("[","")
          step4=step3.replace("]","")
          print(step4)
          step5=teamsidslist.index(int(step4))
          print(step5)
          emote=discord.utils.get(server.emojis,name=teamemojis[step5])
          teamname=teamnames[step5]
          team = discord.utils.get(message.author.guild.roles,id=int(step4))
      for agents in server.members:
        if FA in agents.roles:
          agency.append(agents.id)
      if signeeid not in agency:
          embedno = discord.Embed(title="Transaction Failed!", description=None, color=discord.Color.red())
          embedno.add_field(name="This Transaction Couldn't Be Completed.", value="This player is signed already! Have them demand from their team or get released.")
          await message.channel.send(embed=embedno)
      elif staffroles in message.author.roles:
        for guys in server.members:
          if guys.id==signeeid:
            await guys.add_roles(team)
            await guys.remove_roles(FA)
            if Suspended in guys.roles:
              await message.channel.send("This player is signable, but is ineligible as they are suspended.")
        roster.append(guys)
        roster_size=str(len(roster))
        SignEmbed= discord.Embed(title="VFFL Transactions", description=None, color=discord.Color.green())
        SignEmbed.add_field(name='Successful Transaction.', value=signee+" has been signed to the "+str(emote)+" "+teamname+"!")
        SignEmbed.add_field(name="Roster Size is now ", value=roster_size+'/24', inline=True)
        await message.channel.send(embed=SignEmbed)
        await bot.process_commands(message)
ax lol
  • 59
  • 10

1 Answers1

1

In this line:

elif staffroles in message.author.roles:

You are checking whether the entire list of staffroles is present in message.author.roles, I suppose you want to test if any of the message author's roles are in staffroles instead?

To do that, you can use the any() built-in function like so (as seen in this SO post):

any(role in staffroles for role in message.author.roles)

This line checks if any of the roles the author has is inside of the staffroles list. IF there is at least one such role, it returns true.

Jason Rebelo Neves
  • 1,131
  • 10
  • 20