Skip to content
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

[Bug] Kick through "unbanChatMember" not working for standard/regular groups #201

Open
mrambossek opened this issue Aug 23, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mrambossek
Copy link

heya, trying out the bot, after fiddling for some time to get it running in a docker container, everything seems to work at first glance;
however, when a test user joins and does not fill out the captcha, the console prints:

2024-08-23 11:26:02,447 - __main__ - INFO - [<MYGROUP>] Captcha reply timeout for user <USER>.
2024-08-23 11:26:02,449 - __main__ - INFO - [<MYGROUP>] <UID> join_retries: 1
2024-08-23 11:26:02,449 - __main__ - INFO - [<MYGROUP>] Captcha Fail - Kick - <USER> (<UID>)
2024-08-23 11:26:02,547 - tlgbotutils - ERROR - [<MYGROUP>] Method is available for supergroup and channel chats only
2024-08-23 11:26:02,548 - __main__ - INFO - [<MYGROUP>] Unable to kick
2024-08-23 11:26:02,591 - __main__ - INFO - [<MYGROUP>] Removing msgs from user <USER>...
2024-08-23 11:26:12,528 - tlgbotutils - ERROR - [<MYGROUP>] Message to delete not found

(i have replaced the actual values with for privacy reasons)

im not good with python, but as far as i can tell this comes from tlg_kick_user which in turn leads to unban_chat_member ... and now i'm lost. :)

my group is a "normal" group, not a supergroup.. is that the issue? is there no "normal" kick API, or why is unban_chat_member used in the first place? is there a way to make it work for my group?

thanks & kr

@J-Rios
Copy link
Owner

J-Rios commented Aug 24, 2024

Hi,

Thanks for reporting this, I was unaware of it!

im not good with python, but as far as i can tell this comes from tlg_kick_user which in turn leads to unban_chat_member ... and now i'm lost. :)

Yes, the problem is in the "unban_chat_member()" function, that sends a "unbanChatMember" Bot API Request to kick users, and seems this request is only valid for supergroups and channels...

my group is a "normal" group, not a supergroup.. is that the issue?

Indeed you are facing this issue cause your group is a regular group and not a supergroup (perhaps due it is a private group?). By default, new Telegram groups created are standard, but once it becomes public, or it reaches 200 members, or some settings in the group are changed, them are silently and automatically upgraded into a supergroup.

Note: a regular group has limited functionality and Bots in it work poorly or do not work at all.

is there no "normal" kick API, or why is unban_chat_member used in the first place? is there a way to make it work for my group?

Afraid there is no "kick" request in the Bot API... A couple of years ago, I was using the "ban" request + "unrestrict" request to achive a "kick" behaviour, however it was replaced with the "unbanChatMember" request cause it is more safe to have a kick behaviour just with a single request, and also avoiding some weird issues that could happen if network is not working properly and 1 of this 2 requests is missing.

One possible fix for this is to improve the "tlg_kick_user()" function to apply the approach of "ban + unrestrict requests" if the "unban_chat_member()" fails due "Method is available for supergroup and channel chats only".

However, I have not test this Bot in regular groups from few years ago, so even if we manage to make the kick feature to work, there is no guaranteed that all other features will work properly.

To solve your issue, perhaps you could try to convert that regular group into a supergroup.
For that, try the following:

  1. Set the group as public.
  2. [Optional] Set it back to private if you want to keep the group private.

With this setting change the group should become a supergroup and the Bot will work properly.

Regards ;)

@J-Rios J-Rios added the bug Something isn't working label Aug 24, 2024
@J-Rios J-Rios changed the title kick leads to "Method is available for supergroup and channel chats only" [Bug] kick leads to "Method is available for supergroup and channel chats only" Aug 24, 2024
@J-Rios J-Rios changed the title [Bug] kick leads to "Method is available for supergroup and channel chats only" [Bug] Kick through "unbanChatMember" not working for standard/regular groups Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants