D
D
Dmitry2019-01-13 18:17:02
PHP
Dmitry, 2019-01-13 18:17:02

How to solve api telegram problem with blocking users?

Hello, I wrote a bot that should block absolutely all new chat users (excluding those whose username is in the database)
Here is my code:

$data = json_decode(file_get_contents('php://input'));
    if (isset($data->{'message'}->{'chat'}->{'type'}) && $data->{'message'}->{'chat'}->{'type'} == 'supergroup')
    {
      $id_user = $data->{'message'}->{'new_chat_members'}->{'id'};
      $id_chat = $data->{'message'}->{'chat'}->{'id'};
      $username_chat = $data->{'message'}->{'chat'}->{'username'};
      $username_user = $data->{'message'}->{'new_chat_members'}->{'username'};

      $query_count = mysqli_query($connect, "SELECT * FROM `telegram` WHERE `chat_username` = '".$username_chat."' AND `username` = '".$username_user."'");
      $query_count = mysqli_num_rows($query_count);
      if (!($query_count))
        file_get_contents("https://api.telegram.org/botHASH/restrictChatMember?chat_id=".$id_chat."&user_id=".$id_user);
    }

The problem is that it does not work clearly, it does not ban those who are in the database clearly, but it will ban ordinary users every other time, then not.
What is the problem here? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artemy Family, 2019-08-16
@APTEMOH

permissions needs to be sent

'can_send_messages'         => true,
'can_send_media_messages'   => true,
'can_send_polls'            => true,
'can_send_other_messages'   => true,
'can_add_web_page_previews' => true,
'can_change_info'           => true,
'can_invite_users'          => true,
'can_pin_messages'          => true,

false - to block

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question