Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

How to pass user's id into the decorator as an argument. aiogram

$
0
0

Im writing a simple procedure bot and one of the features requires authorization. Easiest way I found is having an array of telegram user ids and when user wants to execute a command /log it would check if his id is in "admins" list. So I ended up having this:

admins = [123123, 12312]def is_authorized(user_id):    def decorator(func):        @wraps(func)        def wrapper(*args, **kwargs):            if user_id in users:                return func(*args, **kwargs)            else:                return        return wrapper    return decorator@dp.message(Command(commands=["log"]))@is_authorized(message.from_user.id)async def loglast20(message: types.Message):    await bot.send_message(message.from_user.id, 'some logs here')

But the problem is

@is_authorized(message.from_user.id)

'message' is not referenced before usage.How do I pass 'message.from_user.id' as an argument to my is_authorized decorator?Im not really into creating class objects or maintaining sessions, i'd like to keep it simple


Viewing all articles
Browse latest Browse all 13921

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>