如何使用PHP在TelegramBot中发送随机照片?

问题描述 投票:2回答:1

我想在TelegramBot中发送一张随机照片,我写了这段代码,但它不起作用。我该如何解决这个问题?

Code:

$pictures = [
  [
    "file"=>"data/pictures/pic1.jpg",
  ],
  [
    "file"=>"data/pictures/pic2.jpg",
  ]
];

$random_image = $pictures[rand(0, count($pictures) - 1)];
if ($text == "pictest"){
    Bot('SendPhoto',[
        'chat_id' => $chat_id,
        'photo' => $random_image,
    ]);
}
php telegram telegram-bot php-telegram-bot
1个回答
0
投票

在这里,我们可能会失踪:

  • 图像之前的基本域,例如:domain.org/data/pictures/pic1.jpg
  • file$random_image指数 $pictures = [ [ "file" => "data/pictures/pic1.jpg", ], [ "file" => "data/pictures/pic2.jpg", ], ]; $random_image = $pictures[rand(0, count($pictures) - 1)]["file"]; if ($text == "pictest"){ Bot('SendPhoto',[ 'chat_id' => $chat_id, 'photo' => $random_image, ]); }
© www.soinside.com 2019 - 2024. All rights reserved.