#๐Ÿ”’ Logic Error in if statement using disnake.

17 messages ยท Page 1 of 1 (latest)

hearty copper
#
has_ova_role = any(role.id == 826183206469500980 for role in member.roles)
has_advisor_role = any(role.id == 1019241773748461608 for role in member.roles)
has_co_role = any(role.id == 1155698851064324106 for role in member.roles)
has_foxtrot_role = any(role.id == 576727592552366101 for role in member.roles)
has_loa_role = any(role.id == 592627110623969298 for role in member.roles)
joined_timestamp = member.joined_at.timestamp()
current_timestamp = datetime.now().timestamp()

if member and current_points >= amount and has_foxtrot_role and not ( has_advisor_role and not has_co_role and not has_loa_role) and joined_timestamp < (current_timestamp - 2 * 7 * 24 * 60 * 60):

ok so
Essentially, the check needs to be

They need to have the foxtrot role

If they have the advisor, co, or loa role, it should be false
everything is working but the advisor co, or loa stuff
the check is working fine, however i cant get it properly work in the if statement all together

carmine spireBOT
#

@hearty copper

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.

lusty mason
#

don't try to stuff so much stuff into a single if statement

hearty copper
#

yea i probably shouldn't

lusty mason
#

at least do something like ```py
has_required_roles = has_foxtrot_role and not (has_advisor_role and not has_co_role and not has_loa_role)
joined_recently = joined_timestamp >= (current_timestamp - 2 * 7 * 24 * 60 * 60)

if has_required_roles and not joined_recently:

...

#

(note that I got rid of if member because that wasn't doing anything; you already accessed member.joined_at above)

#

now it's a little bit more obvious that has_required_roles is a pretty strange condition.

a and not (b and not c and not d)
is equivalent to
a and (not b or c or d)

hearty copper
#

hold on ill try putting all of it into vars

#

still not properly registering

#

Yea no, even with the vars & changing the logic. its still including people with these roles. Peculiar thing is though, its not everyone, For example, only some people with the co role, or some people with the loa role are showing up.

#

@lusty mason

hybrid orbit
#

Can you paste your updated code?

hearty copper
#
has_ova_role = any(role.id == 826183206469500980 for role in member.roles)
has_advisor_role = any(role.id == 1019241773748461608 for role in member.roles)
has_co_role = any(role.id == 1155698851064324106 for role in member.roles)
has_foxtrot_role = any(role.id == 576727592552366101 for role in member.roles)
has_loa_role = any(role.id == 592627110623969298 for role in member.roles)
joined_timestamp = member.joined_at.timestamp()
current_timestamp = datetime.now().timestamp()
has_required_roles = has_foxtrot_role and (not has_advisor_role or has_co_role or has_loa_role)
joined_recently = joined_timestamp >= (current_timestamp - 2 * 7 * 24 * 60 * 60)

if current_points >= amount and has_required_roles and not joined_recently:
  new_points = current_points - amount
  await func.DataUpdate(self.bot,f"UPDATE points SET points = {new_points} WHERE guild_id = {ctx.guild.id} and user_id = {user_id}")
  able_to_pay.append(member)

if current_points < amount and has_required_roles and not joined_recently:
  unable_to_pay.append(member)
#

holly shit the formatting is bad

#

hold on

carmine spireBOT
#
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.