I’m trying to make a simple bot that mutes users but I’m having some issues with retrieving the user id of a replied message.
I can’t access to user_id because the library is using the from
key like:
def mute_user(update, context):
bot = context.bot
print(update.message.reply_to_message.from.id)
I cannot use the "from" key because it is reserved so it gives me an error.
If i remove the .from.id
, the output will be like this:
[...] 'from': {'is_bot': False, 'username': '*****', 'first_name': '*****', 'id': 150*****}}
How can I access to that id?
2
Answers
I resolved this problem reading the python-telegram-bot documentation
https://python-telegram-bot.readthedocs.io/en/stable/telegram.message.html?highlight=telegram.Message#telegram.Message
I used
update.message.reply_to_message.from_user
instead ofupdate.message.reply_to_message.from
Not sure if this is the answer to what you’re looking for, but since I see you are using dictionaries, most likely nested dictionaries, here is a sample on how to get keys.