unbanChatSenderChat
Returns: TrueOfficial docs ↗
Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.
Parameters
chat_idIntegerStringRequiredUnique identifier for the target chat or username of the target channel (in the format
@channelusername)sender_chat_idIntegerRequiredUnique identifier of the target sender chat
Returns
On success, True is returned.
GramIO Usage
Unban a channel that was previously banned from posting in a supergroup:
ts
// Unban a channel (by numeric ID) from posting in a supergroup
await bot.api.unbanChatSenderChat({
chat_id: -1001234567890, // target supergroup
sender_chat_id: -1009876543210, // the banned channel to unban
});Handle a command to restore a banned channel's posting rights:
ts
bot.command("unbanchannel", async (ctx) => {
// In practice you'd look up the sender_chat_id from your database
const bannedChannelId = -1009876543210;
await bot.api.unbanChatSenderChat({
chat_id: ctx.chat.id,
sender_chat_id: bannedChannelId,
});
await ctx.reply("Channel has been unbanned and can post again.");
});Unban a channel in a target channel by username:
ts
async function restoreChannelAccess(senderChatId: number) {
await bot.api.unbanChatSenderChat({
chat_id: "@mysupergroup",
sender_chat_id: senderChatId,
});
}Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: chat not found | chat_id is invalid, the bot is not in the chat, or the chat no longer exists |
| 400 | Bad Request: sender chat not found | sender_chat_id does not correspond to a known Telegram chat |
| 403 | Forbidden: bot is not an administrator | The bot has no admin status in the target chat |
| 403 | Forbidden: not enough rights to restrict/ban chat member | The bot is an admin but lacks can_restrict_members — grant it in admin settings |
| 429 | Too Many Requests: retry after N | Rate limit hit — check retry_after, use the auto-retry plugin |
TIP
Use GramIO's auto-retry plugin to handle 429 errors automatically.
Tips & Gotchas
- This unbans channels, not users.
unbanChatSenderChatis the counterpart ofbanChatSenderChat— it restores a channel's ability to send messages as itself in a supergroup. For individual users, useunbanChatMember. - Bot must have
can_restrict_members. The bot needs this administrator right to unban sender chats, just as with banning. - Only applicable where channels can post. Supergroups can allow channels to post as sender chats; this method manages that access. It has no effect in basic groups.
- Unban does not automatically resume posting. The channel gains permission to post, but no messages are sent on its behalf — a channel admin must initiate that.
See Also
banChatSenderChat— Ban a channel from posting in a supergroup or channelunbanChatMember— Unban an individual user from a supergroup or channelbanChatMember— Ban an individual user from a supergroup or channelrestrictChatMember— Restrict specific permissions for a membergetChatMember— Check member or sender chat status