replaceStickerInSet
Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling deleteStickerFromSet, then addStickerToSet, then setStickerPositionInSet. Returns True on success.
Parameters
user_idIntegerRequiredUser identifier of the sticker set owner
nameStringRequiredSticker set name
old_stickerStringRequiredFile identifier of the replaced sticker
A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set remains unchanged.
Returns
On success, True is returned.
GramIO Usage
Replace a sticker using a new local file:
ts
await bot.api.replaceStickerInSet({
user_id: 123456789,
name: "MyStickerSet_by_mybot",
old_sticker: "CAACAgIAAxkBAAIBb2YKp_OLD_FILE_ID",
sticker: {
sticker: await MediaUpload.path("./updated_sticker.webp"),
format: "static",
emoji_list: ["✨"],
},
});Replace with an existing sticker by file_id, adding keywords:
ts
await bot.api.replaceStickerInSet({
user_id: 123456789,
name: "MyStickerSet_by_mybot",
old_sticker: "CAACAgIAAxkBAAIBb2YKp_OLD",
sticker: {
sticker: "CAACAgIAAxkBAAIBb2YKp_NEW",
format: "static",
emoji_list: ["🎉", "🥳"],
keywords: ["party", "celebrate", "happy"],
},
});Replace a video sticker uploaded from a URL:
ts
await bot.api.replaceStickerInSet({
user_id: 123456789,
name: "MyVideoSet_by_mybot",
old_sticker: "CAACAgIAAxkBAAIBb2YKp_OLD_VIDEO",
sticker: {
sticker: await MediaUpload.url("https://example.com/new_sticker.webm"),
format: "video",
emoji_list: ["🔥"],
},
});Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: STICKERSET_INVALID | Sticker set doesn't exist or wasn't created by this bot — verify name ends with _by_<botusername> |
| 400 | Bad Request: STICKER_EMOJI_INVALID | emoji_list contains an invalid or non-emoji character — must be actual emoji codepoints |
| 400 | Bad Request: STICKER_PNG_DIMENSIONS | Static sticker dimensions are wrong — must be exactly 512×512 px |
| 400 | Bad Request: STICKER_FILE_INVALID | The replacement file is corrupt, wrong format, or exceeds size limits |
| 400 | Bad Request: wrong file identifier/HTTP URL specified | The old_sticker file_id is invalid or doesn't belong to this sticker set |
| 400 | Bad Request: USER_NOT_FOUND | user_id doesn't correspond to a known Telegram user |
| 429 | Too Many Requests: retry after N | Rate limit hit — check retry_after, use auto-retry plugin |
TIP
Use GramIO's auto-retry plugin to handle 429 errors automatically.
Tips & Gotchas
- The operation is atomic in position.
replaceStickerInSetpreserves the original sticker's position in the set. This is more reliable than manually calling delete + add + reposition, which can fail midway and leave the set inconsistent. - The sticker set must be owned by the bot. The
user_idis the set owner (the person who requested it), but the bot must have created the set viacreateNewStickerSet. - Format must match the set type. You cannot replace a static sticker with a video sticker. The
formatinInputStickermust match the set's original type. - Duplicate replacement is a no-op. If
stickeris the exact same file already in the set, the method returnsTruebut the set is not modified. old_stickeris the file_id of the sticker to remove. Get current sticker file IDs fromgetStickerSet— eachStickerobject instickers[]has afile_id.emoji_listaccepts 1–20 emojis. The new sticker's emoji associations are set fresh — the old sticker's emojis are not inherited.
See Also
addStickerToSet— Add a new sticker without replacing an existing onedeleteStickerFromSet— Remove a sticker permanently from a setsetStickerPositionInSet— Reorder a sticker within a setcreateNewStickerSet— Create a new sticker setgetStickerSet— Retrieve a sticker set and its currentfile_idvaluesInputSticker— The object structure for sticker dataStickerSet— Sticker set type reference- MediaUpload guide — How to upload files from disk, URL, or buffer in GramIO