Skip to content

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_idIntegerStringRequired
Unique identifier for the target chat or username of the target channel (in the format @channelusername)
sender_chat_idIntegerRequired
Unique 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

CodeErrorCause
400Bad Request: chat not foundchat_id is invalid, the bot is not in the chat, or the chat no longer exists
400Bad Request: sender chat not foundsender_chat_id does not correspond to a known Telegram chat
403Forbidden: bot is not an administratorThe bot has no admin status in the target chat
403Forbidden: not enough rights to restrict/ban chat memberThe bot is an admin but lacks can_restrict_members — grant it in admin settings
429Too Many Requests: retry after NRate 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. unbanChatSenderChat is the counterpart of banChatSenderChat — it restores a channel's ability to send messages as itself in a supergroup. For individual users, use unbanChatMember.
  • 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