setMyProfilePhoto
设置机器人的头像。
返回值: 调用成功时返回 True。
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
photo | InputProfilePhoto | 是 | 头像 URL 或 file_id |
请求示例
curl
curl -s -X POST "https://api.telegram.org/bot$TOKEN/setMyProfilePhoto" \
-H "Content-Type: application/json" \
-d '{"photo":{"type":"static","photo":"attach://photo"}}'
Python
import requests
TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
f"https://api.telegram.org/bot{TOKEN}/setMyProfilePhoto",
json={
"photo": {
"type": "static",
"photo": "attach://photo"
}
},
timeout=30,
)
print(resp.json())
JavaScript
const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/setMyProfilePhoto`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"photo": {
"type": "static",
"photo": "attach://photo"
}
}),
});
console.log(await res.json());
分步教程: Telegram 机器人教程:从零创建 Telegram 机器人并发送第一条消息
相关方法
getMe返回机器人信息。getMyCommands返回机器人当前的命令列表。setMyCommands设置机器人的命令列表。deleteMyCommands删除机器人命令。getMyName返回机器人的名称。setMyName设置机器人的名称。getMyDescription返回机器人的描述。setMyDescription设置机器人的描述。getMyShortDescription返回机器人的简短描述。setMyShortDescription设置机器人的简短描述。removeMyProfilePhoto移除机器人的头像。getUserProfilePhotos返回用户的头像列表。