#🔒 I'm trying to make a discord bot that checks roles but I'm struggling with it

28 messages · Page 1 of 1 (latest)

signal torrent
#

Hi, I've been trying for the last 4 days to make a discord bot with discord.py that checks if a member has two roles, and after those conditions are met the bot will automatically give the verified role and erase the other two roles alongside the unverified role. This is how my code looks like right now:

https://paste.pythondiscord.com/6T4Q

carmine sableBOT
#

@signal torrent

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

wanton ice
signal torrent
#

I had to scratch everything because the original code was not working

wanton ice
#

Alright. Have a look at some decorators. I believe there is a has all roles option.

#

Also maybe triple check your if ststement there.
You want to give a role when 3 roles are present, and then remove the 3 roles?

signal torrent
wanton ice
#

Thats still the same no?
They need to have 3 roles,
You give it another role,
Remove the original 3 roles

signal torrent
#

Yee, basically

wanton ice
#

So if all(role in member.roles for role in requiredroles):
Disclaimer, not sure if member.roles is a real thing.

signal torrent
#

Gonna be real with ya homie. This bot logic was made with chatgpt. But everything was failing once I tried it so I scrapped everything

#

Rn I'm trying to craft the code myself but I dunno what is the command for this

wanton ice
#

There’s @commands.has_role()
Not sure if it csn be used with unpacking a list or not to check on all roles

wanton ice
carmine sableBOT
#
The or-gotcha

When checking if something is equal to one thing or another, you might think that this is possible:

# Incorrect...
if favorite_fruit == 'grapefruit' or 'lemon':
    print("That's a weird favorite fruit to have.")

While this makes sense in English, it may not behave the way you would expect. In Python, you should have complete instructions on both sides of the logical operator.

So, if you want to check if something is equal to one thing or another, there are two common ways:

# Like this...
if favorite_fruit == 'grapefruit' or favorite_fruit == 'lemon':
    print("That's a weird favorite fruit to have.")

# ...or like this.
if favorite_fruit in ('grapefruit', 'lemon'):
    print("That's a weird favorite fruit to have.")
wanton ice
#

Also. == will fail because you want member.roles to be at least 3, and role1 will be 1 role.
So they’ll never equal

signal torrent
#

Ok, now I need to add verified role and delete the other 3

wanton ice
#

You can probably
member.add_roles(role)

#

bot.remove_roles(user, role)

#

And those roles are Role objects. You need to get those first

signal torrent
#

Alright, this is what I crafted. Sorry for the delay I was getting lunch

wanton ice
#

The commands.has role is the same as your if statement.
Although its not really used correctly atm.
In any case it would be either or

#

Also I dont see why you need to remove a role and add a role..?
Cant it just be 2 lines?

carmine sableBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.