Skip to content

Commit 46f777e

Browse files
authored
Merge pull request #83 from Code4GovTech/fix/#432/delayed-role-assignment
Fix/#432/delayed role assignment
2 parents b7a57db + 643487d commit 46f777e

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

cogs/userInteractions.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self, bot) -> None:
1717
self.bot = bot
1818
self.update_contributors.start()
1919

20-
@tasks.loop(minutes=10)
20+
@tasks.loop(minutes=60)
2121
async def update_contributors(self):
2222
print("update_contributors running")
2323
contributors = SupabaseClient().read_all("contributors_registration")
@@ -26,16 +26,19 @@ async def update_contributors(self):
2626
contributor_role = guild.get_role(VERIFIED_CONTRIBUTOR_ROLE_ID)
2727
for contributor in contributors:
2828
discord_id = contributor["discord_id"]
29-
member = guild.get_member(discord_id)
30-
if member:
29+
try:
30+
member = await guild.fetch_member(discord_id)
3131
if contributor_role not in member.roles:
32-
await member.add_roles(contributor_role)
33-
print(f"Given {contributor_role.name} Role to {member.name}")
32+
try:
33+
await member.add_roles(contributor_role)
34+
print(f"Gave {contributor_role.name} role to {member.name}")
35+
except Exception as e:
36+
print(f"{member.name} could not be given verified contributor role")
3437
else:
35-
print(f"{member.name} is already {contributor_role.name}")
36-
else:
37-
print(f"{discord_id} is not a member on discord")
38-
## TODO delete from supabase as well?
38+
print(f"{member.name} is already a {contributor_role.name}")
39+
except:
40+
print(f"User with discord_id: {discord_id} is not a member of our server anymore")
41+
# TODO delete from supabase as well?
3942
return
4043

4144
@commands.command(aliases=["badges"])

main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ async def on_submit(self, interaction: discord.Interaction):
6161
"country": self.country.value
6262
}
6363
supaClient = SupabaseClient()
64-
response = (supaClient.client.table("contributors_discord")
65-
.upsert(user_data, on_conflict="discord_id").execute())
66-
print("DB updated for user:", response.data[0]["discord_id"])
64+
try:
65+
response = (supaClient.client.table("contributors_discord")
66+
.upsert(user_data, on_conflict="discord_id").execute())
67+
print("DB updated for user:", response.data[0]["discord_id"])
68+
except Exception as e:
69+
print("Failed to update credentials for user: "+e)
6770

6871
verifiedContributorRoleID = int(os.getenv("VERIFIED_ROLE_ID"))
6972
if verifiedContributorRoleID in [role.id for role in user.roles]:

0 commit comments

Comments
 (0)