【问题标题】:Telegram Bot join new user to kick and keep whitelist a member of private group?Telegram Bot 加入新用户以踢白名单并保留私人组的成员?
【发布时间】:2020-08-09 16:00:55
【问题描述】:

我正在尝试 Webhook ex 的电报机器人。新用户加入检查数据库不是我的会员来踢用户!

<?php
$API_KEY = 'token';
define('API_KEY', $API_KEY);

function bot($method,$datas=[]){
$url = "https://api.telegram.org/bot" . API_KEY . "/" . $method;
$ch  = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $datas);
$res = curl_exec($ch);
if (curl_error($ch)) {
    var_dump(curl_error($ch));
} else {
    return json_decode($res);
}
}

$update     = json_decode(file_get_contents('php://input'));
$message    = $update->message;
$text       = $message->text;
$chat_id    = $message->chat->id;
$from_id    = $message->from->id;
$new_member = $message->new_chat_member->id;
$memberid   = file_get_contents('whitelist.txt'); //put userid in whitelist.txt
$whitelist  = explode("\n", $memberid);

if ($new_member) {
    if (!in_array($chat_id, $whitelist)) {
           bot('kickChatMember',[
          'chat_id'=>$chat_id,
          'user_id'=>$message->new_chat_member->id]);
    }
}
?>

我试过它给了我错误结果“数组”有什么错误的格式 json 这段代码?

【问题讨论】:

    标签: telegram telegram-bot php-telegram-bot telegram-webhook


    【解决方案1】:

    您可以尝试使用$update["message"] 而不是$update-&gt;message;,并对其余变量使用相同的语法。对我来说,它工作得非常好。

    【讨论】:

      猜你喜欢
      • 2019-01-16
      • 1970-01-01
      • 2019-01-12
      • 1970-01-01
      • 2020-03-31
      • 2018-08-11
      • 2021-08-08
      • 2018-12-18
      • 1970-01-01
      相关资源
      最近更新 更多