#Not getting custom roles from new members

1 messages · Page 1 of 1 (latest)

grand fjord
#

I'm trying to check the roles of members x seconds after they join the server.
I'm using a listener for hikari.MemberCreateEvent and then attempt to get the roles through event.member.get_roles(), but it only returns the everyone role. I also tried event.member.fetch_roles(), but got the same result.

Anyone know why this could be happening/how to fix it?

fresh crest
#

Well getting the obvious out of the way, do they actually have any rolls to get?

#

Actually im not sure, but for someone who knows, is the member object from the event just a snapshot from when they join? If so there wouldn't be any roles except for the "everyone" one anyway, right?

grand fjord
grand fjord
split sphinx
# grand fjord this would've been my guess aswell, but I would also think that `fetch_roles()` ...

it looks like you are using it on the event though? Have you tried using the rest api?
I believe when I used hikari.MemberUpdateEvent it seemed like it was the snapshot at the time. I was using the role_ids from member and old_member to get the id of which role was added. From memory I saw 2 events and triggers when I removed 2 roles just clicking the x on the dots (so definitely long enough to be separate event for machines but may not for human).

azure dove
#

@grand fjord if you are using fetch_roles, then you are hitting the API endpoint and should get up to date information

grand fjord
#

ok so yeah it seems to work with MemberUpdateEvent, but there are two of them for some reason. The output in the screenshot comes from a user joining a server and selecting a bunch of roles during onboarding. The onboarding process is completed and the user has those roles before the 20 seconds are up.

@component.with_listener(hikari.MemberCreateEvent)
async def check_roles_join(event: hikari.MemberCreateEvent):
    print(f"Member {event.member.id} Joined")
    sleep(20)
    print("Timer is up")
    roles = await event.member.fetch_roles()
    print(f"Member {event.member.id} fetch roles:", roles)
    print(f"Member {event.member.id} get roles:", event.member.get_roles())
    print(f"Member {event.member.id} role IDs:", event.member.role_ids)


@component.with_listener(hikari.MemberUpdateEvent)
async def check_roles_update(event: hikari.MemberUpdateEvent):
    print(f"Member {event.member.id} updated")
    roles = event.member.role_ids
    print(f"Member {event.member.id} roles after update:", roles)
grand fjord
azure dove
#

Never use sleep(20), it's blocking and will hang your application

#

Use await asyncio.sleep(20)

#

And if the rest doesn't report new roles, raise that issue with discord, as it fetches directly from them