for invite in invites_before_join:
try:
if invite.uses < find_invite_by_code(invites_after_join, invite.code).uses:
except NameError as e:
pass
print('Не нашёл код')
if invite.uses < find_invite_by_code(invites_after_join, invite.code).uses:в некоторых случаях выскакивает ошибка NameError: name 'uses' is not defined