如何使用 PHP 在 TelegramBot 中发送随机照片?
How to send a random photo in TelegramBot using PHP?
我想在 TelegramBot 中发送一张随机照片,我写了这段代码,但它不起作用。我该如何解决这个问题?
代码:
$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,
]);
}
这里,我们可能遗漏了:
图像前的基域,如:domain.org/data/pictures/pic1.jpg
或 $random_image
中的 file
索引
$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,
]);
}
我想在 TelegramBot 中发送一张随机照片,我写了这段代码,但它不起作用。我该如何解决这个问题?
代码:
$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,
]);
}
这里,我们可能遗漏了:
图像前的基域,如:
domain.org/data/pictures/pic1.jpg
或
中的$random_image
file
索引$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, ]); }