T
T
Telmor2021-11-29 19:24:59
Python
Telmor, 2021-11-29 19:24:59

What to do if the bot does not find the user on the server?

I have a code that checks the database every minute for time out. And if the time is up, it removes the role and deletes the line from the database.
And after I got the user id, I want to convert it to an object. But I get an error:

member = main_guild.get_member(member_id)
AttributeError: 'NoneType' object has no attribute 'get_member'


The code:
@tasks.loop(minutes=1.0)
    async def mutes(self):
        ended = self.nakaz.find({'mute_time': {'$lte': time.time()}})
        for mute in ended: 
            main_guild = self.bot.get_guild(820618566163628034)
            member_id = mute["_id"]
            print(member_id)
            member = main_guild.get_member(member_id)
            muted = main_guild.get_role(913833814021787709)
            await member.remove_roles(muted)
            self.nakaz.delete_one(mute)


Please help me solve this problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2021-11-30
@Vindicar

member = main_guild.get_member(member_id)
AttributeError: 'NoneType' object has no attribute 'get_member'
Well, guess what, there is no such guild. ID accurately not mixed up?
Also, are you sure the function doesn't run before the bot has connected?

C
copyhold, 2015-05-07
@copyhold

You can't see the hash on the server.
So only site.ru/forum/read.php?2,184641,184647 will come to the server
, and the redirect will be

rewriterule ^forum/read\.php\?2,184641,184647 /article [r=301,l]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question