New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] Append/Update on ChatPermissions #1834
Comments
Related to #1803 (see this comment): TL;DR: right now, you need to set all the permissions to About "merging" current = context.bot.getChat(chat_id).permissions
current.can_send_polls = True
current.can_send_media = False
...
context.bot.set_chat_permission(chat_id = chat_id, permissions = current) Alternatively, if you want to stick with the dictionary approach: current = context.bot.getChat(chat_id).permissions
new = {'can_send_polls': True}
permissions_kwargs = {'can_send_messages': None, 'can_send_media_messages': None, 'can_send_polls': None, 'can_send_other_messages': None, 'can_add_web_page_previews': None, 'can_change_info': None, 'can_invite_users': None, 'can_pin_messages': None}
permissions_kwargs .update(current)
permissions_kwargs .update(new)
permissions = ChatPermission(**permissions_kwargs) # creates a ChatPermissions instance based on your kwargs
context.bot.set_chat_permission(chat_id = chat_id, permissions = current) |
Thanks for your explain and example code, now everything was fine, here is my final code
Result are
|
Also it seems disable |
Can confirm that something is wrong there. However, this is a Telegram issue. All PTB can do, is pass the values to the API. I get the same results when making simple http requests in the browser. Maybe contact @botsupport about it … Also, keep in mind that e.g. |
I can't restrict users from messaging ( But un-restricting ( My function contains ` msg = update.message.reply_to_message
|
Ok, so it looks like to restrict a member from sending a message, we have to restrict 4 other permissions along with it, so previous code :
updated code :
the updated code works like charm 👍🏽 |
Issue I am facing
I am facing issue when trying to set permission for send poll to True
chat.set_permissions(permission=ChatPermissions(can_send_polls=True))
Then send media, send stickers and gifs, and embed links are turned off.
Because it should not, so i am going to check current permission and replace to new permission and set new one.
And now i am stuck at ChatPermission, since it wasn't dict. So i can't merge or append at ChatPermission.
Traceback to the issue
changed default permissions
+Send polls
−Send media
−Send stickers & GIFs
−Embed links
Related part of your code
doing chat.set_permissions(permission=permissions) will got error since set_permissions is converting to_dict() at
python-telegram-bot/telegram/bot.py
Line 2935 in 16613d7
The text was updated successfully, but these errors were encountered: