deleteStickerFromSet
Returns: TrueOfficial docs ↗
Use this method to delete a sticker from a set created by the bot. Returns True on success.
Parameters
stickerStringRequiredFile identifier of the sticker
Returns
On success, True is returned.
GramIO Usage
ts
// Delete a sticker from a bot-owned set by file_id
await bot.api.deleteStickerFromSet({
sticker: "CAACAgIAAxkBAAIBZWXk8s...",
});ts
// Get the sticker set, then delete the first sticker
const stickerSet = await bot.api.getStickerSet({ name: "my_pack_by_mybot" });
if (stickerSet.stickers.length > 0) {
await bot.api.deleteStickerFromSet({
sticker: stickerSet.stickers[0].file_id,
});
}ts
// Handle a sticker message and remove it from its set
bot.on("message", async (ctx) => {
if (ctx.sticker && ctx.sticker.setName) {
await bot.api.deleteStickerFromSet({
sticker: ctx.sticker.fileId,
});
await ctx.send("Sticker removed from its set.");
}
});Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: STICKER_ID_INVALID | The sticker file_id is malformed, expired, or belongs to a different bot's context |
| 400 | Bad Request: STICKERSET_INVALID | The sticker set the sticker belongs to was not created by this bot |
| 400 | Bad Request: not enough rights | The bot does not own the sticker set that contains this sticker |
| 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
- Only works on bot-owned sticker sets. You can only delete stickers from sets that were created by your bot. Attempting to delete stickers from any other set returns an error.
- Use
file_idnotfile_unique_id. Thestickerparameter requires thefile_idstring (context-specific), notfile_unique_id(which is stable but not accepted here). - Deleting the last sticker doesn't delete the set. An empty sticker set still exists — use
deleteStickerSetto remove it entirely. - Get sticker
file_idviagetStickerSet. If you don't have the file_id at hand, usegetStickerSetto retrieve the full sticker list and extractfile_idfrom each sticker. - Sticker type must be consistent within a set. If the set was created as animated or video stickers, ensure remaining stickers stay consistent — mixing types is not allowed.
See Also
- deleteStickerSet — delete an entire sticker set
- addStickerToSet — add a new sticker to an existing set
- getStickerSet — retrieve a sticker set and its stickers
- createNewStickerSet — create a new sticker set
- StickerSet — sticker set object reference