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:
#🔒 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
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.
Closes after a period of inactivity, or when you send !close.
I see.
Where’s the rest of the bot logic etc?
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?
No. You see, all my members have the unverified role by default. So I need to check if they get the ID Verified and the Pledge Accepted role in order to let em in. And after that it has to delete those 3 roles (Unverified, ID, Pledge) and give the verified role
Thats still the same no?
They need to have 3 roles,
You give it another role,
Remove the original 3 roles
Yee, basically
So if all(role in member.roles for role in requiredroles):
Disclaimer, not sure if member.roles is a real thing.
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
There’s @commands.has_role()
Not sure if it csn be used with unpacking a list or not to check on all roles
!or
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.")
Also. == will fail because you want member.roles to be at least 3, and role1 will be 1 role.
So they’ll never equal
Ok, now I need to add verified role and delete the other 3
You can probably
member.add_roles(role)
bot.remove_roles(user, role)
And those roles are Role objects. You need to get those first
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?
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.