revokeChatInviteLink
Returns: ChatInviteLinkOfficial docs ↗
Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Returns the revoked invite link as ChatInviteLink object.
Parameters
chat_idIntegerStringRequiredUnique identifier of the target chat or username of the target channel (in the format
@channelusername)invite_linkStringRequiredThe invite link to revoke
Returns
On success, the ChatInviteLink object is returned.
GramIO Usage
Revoke a specific invite link:
ts
const revoked = await bot.api.revokeChatInviteLink({
chat_id: "@mychannel",
invite_link: "https://t.me/+abc123def456",
});
console.log(revoked.is_revoked); // true
console.log(revoked.invite_link); // the now-inactive linkCreate a limited invite link and revoke it after use:
ts
// Create a 10-use invite link for a campaign
const link = await bot.api.createChatInviteLink({
chat_id: -1001234567890,
member_limit: 10,
name: "Campaign link",
});
// ... users join via link.invite_link ...
// When done, revoke it to prevent further joins
const revoked = await bot.api.revokeChatInviteLink({
chat_id: -1001234567890,
invite_link: link.invite_link,
});
console.log(`Link revoked: ${revoked.invite_link}`);Revoke the primary link (a new one is auto-generated):
ts
// Get the primary link first
const chat = await bot.api.getChat({ chat_id: -1001234567890 });
const primaryLink = chat.invite_link;
if (primaryLink) {
// Revoking the primary link auto-creates a fresh one
await bot.api.revokeChatInviteLink({
chat_id: -1001234567890,
invite_link: primaryLink,
});
}Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: chat not found | chat_id is invalid or the bot is not a member of the chat |
| 400 | Bad Request: INVITE_HASH_INVALID | invite_link has an invalid format — must be a t.me/+... or t.me/joinchat/... URL |
| 400 | Bad Request: INVITE_HASH_EXPIRED | Link was already revoked — check is_revoked on the ChatInviteLink before calling again |
| 400 | Bad Request: not enough rights to create invite link | Bot lacks the can_invite_users administrator right |
| 403 | Forbidden: not enough rights | Bot is not an administrator in the chat |
| 403 | Forbidden: bot is not a member of the channel chat | Bot was removed from the channel |
| 429 | Too Many Requests: retry after N | Rate limit hit — check retry_after, use auto-retry plugin |
Tips & Gotchas
- Only links created by your bot can be revoked. You cannot revoke invite links created by other admins. Use
exportChatInviteLinkto manage the primary link. - Revoking the primary link auto-generates a replacement. The new primary link is returned as
chat.invite_linkon subsequentgetChatcalls — you do not need to callexportChatInviteLinkseparately. - The returned
ChatInviteLinkhasis_revoked: true. Use this field to verify the operation succeeded, and to confirm the link is no longer usable before attempting to revoke it. - Users who already joined via the link are not affected. Revoking a link only prevents new users from joining — it does not remove anyone from the chat.
- Subscription links cannot be revoked this way. If the link has
subscription_period, use the appropriate subscription management methods. - Check expiry before revoking. Links with
expire_datein the past ormember_limitreached are already inactive — revoking them again is a no-op that may throwINVITE_HASH_EXPIRED.
See Also
createChatInviteLink— Create a new invite link (with optional limits, expiry, or approval)editChatInviteLink— Edit an existing invite link's settingsexportChatInviteLink— Generate or refresh the primary invite linkChatInviteLink— The full invite link object structure