Skip to content

setChatPhoto

Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns True on success.

Parameters

chat_idIntegerStringRequired
Unique identifier for the target chat or username of the target channel (in the format @channelusername)
photoInputFileRequired📎 Files
New chat photo, uploaded using multipart/form-data

Returns

On success, True is returned.

GramIO Usage

ts
// Upload a new chat photo from the local filesystem
await 
bot
.
api
.
setChatPhoto
({
chat_id
: -1001234567890,
photo
: await
MediaUpload
.
path
("./new-chat-photo.jpg"),
});
ts
// Upload a chat photo from a URL
await 
bot
.
api
.
setChatPhoto
({
chat_id
: "@mychannel",
photo
: await
MediaUpload
.
url
("https://example.com/logo.png"),
});
ts
// Upload a chat photo from a Buffer
async function 
setPhotoFromBuffer
(
chatId
: number,
imageBuffer
:
Buffer
) {
await
bot
.
api
.
setChatPhoto
({
chat_id
:
chatId
,
photo
:
MediaUpload
.
buffer
(
imageBuffer
, "chat-photo.jpg"),
}); }
ts
// From a message context — set the current chat's photo
bot
.
command
("setphoto", async (
ctx
) => {
await
ctx
.
setChatPhoto
(await
MediaUpload
.
path
("./branding/logo.jpg"));
await
ctx
.
send
("Chat photo updated!");
});

Errors

CodeErrorCause
400Bad Request: chat not foundInvalid or inaccessible chat_id
400Bad Request: PHOTO_INVALID_DIMENSIONSImage dimensions are too large or unsupported
400Bad Request: can't change chat photo of private chatschat_id is a private user chat — photos can only be set on groups, supergroups, and channels
400Bad Request: wrong file identifier/HTTP URL specifiedTried to pass a file_id or non-downloadable URL — only direct file uploads are accepted
403Forbidden: not enough rights to change chat photoBot lacks the can_change_info admin right
403Forbidden: bot is not a member of the channel chatBot was removed from the channel

Tips & Gotchas

  • Only fresh file uploads are accepted. Unlike sendPhoto, you cannot reuse a file_id — the photo parameter must always be an uploaded file (MediaUpload.path, MediaUpload.url, or MediaUpload.buffer). Using a file_id string will return wrong file identifier.
  • Private chats are not supported. The method explicitly fails on private (user-to-bot) chats. It works on groups, supergroups, and channels only.
  • can_change_info right is required. Ensure the bot's admin role grants this right, otherwise you'll receive 403 not enough rights.
  • MediaUpload.path and MediaUpload.url are async — always await them. MediaUpload.buffer(buf, filename) is synchronous.
  • Use deleteChatPhoto to remove the photo. There's no "clear" option in setChatPhoto; use the dedicated deleteChatPhoto method to revert to no photo.
  • JPEG/PNG formats work best. Telegram recommends a square image; very wide or tall images may be cropped automatically.

See Also