0
votes

I have this code

async def allroles(ctx):
  output2 = ""
  server = ctx.message.guild
  role_id = server.roles[0]

  for role in server.roles:
    if role_id == 640586288029892618:
      print("it´s everyone role")
    else:
      output2 +=f"{role.name} \n"
  await ctx.send(output2)

where 640586288029892618 == @everyone I wanna write every role except everyone, but when I tried this it just wrote all roles include everyone, so I guess my try to not write it was wrong (and if there is option to instead ID of everyone use role_name so I don´t have to change it for every @everyone server role but write into

if role.name == "@everyone":
    Skip
else:
    output2 +=f"{role.name} \n"
await ctx.send(output2)

It would be nice. Thank you for helping me out!

1

1 Answers

1
votes

So basically you are doing something wrong here

    if role_id == 640586288029892618:
      print("it´s everyone role")

The role_id = server.roles[0] returns the some weird data here(I Don't remember the name) so try replacing if role_id == 640586288029892618: with if role_id.id == 640586288029892618:

hope it solves your problem, else just ping me up

Edit: since u asked for a easier method than putting role id every time
well for most of the roles it may work fine but when u put emojis in role names u might face difficulty while naming roles in code, and why go for hard coding when u can do it by simply adding another argument like
Make sure u import Role Class


    async def allroles(ctx, role_to_check:Role):
          //some code here
          for role in server.roles:
            if role.id == role_to_check.id:
               print("it´s everyone role")

Hope this solves your answer man :)