Telegram Permission Logic with Telethon
Environment Description
Telegram interface sets the default permissions for the group.
The join group verification bot (tg-join-group-exam-bot.py) sets permissions in Exceptions after a new member passes the verification.
The Clear Exceptions tool (tg-clean-exceptions.py) reads the group's default permissions, then reads the permissions of a user in Exceptions.
Test Process
Case 1.
Group default permissions
music - Close
voice messages - Close
tg-join-group-exam-bot.py sets permission
can_send_audios=False,
can_send_voice_notes=False,
After the new member passes the verification, the record in Exceptions is like this, which meets the expectation
tg-clean-exceptions.py
What is read out by default_rights = entity.default_banned_rights
What is read out by rights = getattr(p.participant, 'banned_rights', None)
You can see the default permissions are correct. This property is default_banned_rights. So True means Close.But the user's permissions read from Exceptions are wrong. False means Open.
Case 2.
Group default permissions
music - Close
voice messages - Close
tg-join-group-exam-bot.py sets permission
can_send_audios=True, (meaning Open)
can_send_voice_notes=True, (meaning Open)
After the new member passes the verification, the record in Exceptions is like this, does not meet the expectation.
Because the permission set in the code above is True, these two permissions should be granted. But the Telegram interface shows they are not.
tg-clean-exceptions.py
What is read out by default_rights = entity.default_banned_rights
What is read out by rights = getattr(p.participant, 'banned_rights', None)
In the default permissions, both of these values are True, meaning Close. This is consistent with the actual settings.
The value of the user's permissions read from Exceptions is False, meaning Open. Inconsistent with the interface. Consistent with the tg-join-group-exam-bot.py code.
Case 3.
Group default permissions
music - Open
voice messages - Open
tg-join-group-exam-bot.py sets permission
can_send_audios=False,
can_send_voice_notes=False,
After a new member passes verification, the record in Exceptions looks like this. Does not match expectations.
Because the permission set in the code above is False, these two permissions should not exist. Yet the Telegram interface shows they do.
tg-clean-exceptions.py
What does default_rights = entity.default_banned_rights read
What does rights = getattr(p.participant, 'banned_rights', None) read
The read result is consistent with what is displayed on the Telegram interface.In the read Exceptions, the value of the user's permission is False, meaning Open. Consistent with the interface. Inconsistent with the tg-join-group-exam-bot.py code.
Case 4.
Group default permissions
music - Open
voice messages - Open
tg-join-group-exam-bot.py sets permission
can_send_audios=True,
can_send_voice_notes=True,
After a new member passes verification, the record in Exceptions looks like this. Matches expectations.
tg-clean-exceptions.py
What does default_rights = entity.default_banned_rights read
What does rights = getattr(p.participant, 'banned_rights', None) read
All correct. False means Open, has this permission.Summary
When using the Telethon and Python Telegram Bot libraries to read and set the group user permissions Music and Voice Messages (i.e., audio and voice_notes), both of these permissions should be kept as Open.
Note: Current library version
pip3 show telethon
Name: Telethon
Version: 1.41.2
pip3 show python-telegram-bot
Name: python-telegram-bot
Version: 22.5
========
Related Recommendations
"Telegram anti-spam bot requires CAPTCHA when speaking in the group, efficiency optimization, verified user list cached in memory"
"Telegram anti-spam bot related feature: kick users without speaking permission from the group's Exceptions list"
"Telegram anti-spam bot related feature: kick users without speaking permission from the group's Exceptions list"











