#get_guild() always returns None

1 messages · Page 1 of 1 (latest)

manic bear
#

Hi,

whenever I use the get_guild() function to get a Guild object the returned Optional is empty.
This also happens when I try to get the info directly from the cache.
This started happening after I set up the GUILD_MEMBERS intent in the developer portal.

Is this expected behaviour? Any ideas on how to fix this?

red forge
#

can you show your bots constructor?

manic bear
#

Do you mean

    token="...",
    default_enabled_guilds=(test_server_id),
    intents=Intents.GUILD_MEMBERS
)```
red forge
#

yes

#

your issue is that you only specified one intent

#

you maybe want to do ```py
intents = hikari.Intents.ALL_UNPRIVILEDGED | hikari.Intents.GUILD_MEMBERS

manic bear
#

thanks, I'll try that

#

It did not work

red forge
#

describe "it did not work" please :)

manic bear
#

I get the same result as before. The Optional[GatewayGuild] is still empty.

red forge
#

did you restart your bot?

manic bear
#

have you tried off and on again? yes

red forge
#

mind showing the code?

manic bear
#

Sorry, I was away over Easter. The function looks like this:

def check_permissions(guild: GatewayGuild, bot_user: OwnUser, req_perms: Flag) -> bool:
    bot_role = guild.get_role(bot_user)
    if (bot_role.permissions & req_perms) == req_perms:
        return True
    return False

Called from:

@bot.listen(events.MemberCreateEvent)
async def on_member_join(event: events.MemberCreateEvent):
    print(">>> Captured MemberCreateEvent")
    print(event.member)

    if not check_permissions(event.member.get_guild(), bot.get_me(), required_perms):
        raise errors.UnauthorizedError(
            f"{bot.get_me().mention} has incomplete permissions.")

    await assign_new_role(event.member)
    await welcome_message(event.member)
manic bear
#

I somehow managed to resolve this issue by removing the bot's GUILD_MEMBERS intent and then adding it back in. Still got permission issues, but that's a different problem.