Skip to content

Group Administration

Group management surfaces

Use these shortcuts when a bot moderates groups, supergroups, join requests, or member permissions.

Member controls

Ban, unban, restrict, and promote members from Context helpers.

Permissions

Set default chat permissions and moderation policy.

Join requests

Approve or decline users before they enter the group.

VibeGram provides Context shortcuts for common group and supergroup management tasks.

Banning & Unbanning

typescript
// Ban a user
bot.command('ban', async ctx => {
    const userId = ctx.message?.reply_to_message?.from?.id;
    if (!userId) return ctx.reply('Reply to a message to ban the user.');

    await ctx.banChatMember(userId);
    await ctx.reply('User banned.');
});

// Unban a user
bot.command('unban', async ctx => {
    const userId = parseInt(ctx.command?.args?.[0] || '0');
    await ctx.unbanChatMember(userId, { only_if_banned: true });
    await ctx.reply('User unbanned.');
});

Restricting Members

typescript
bot.command('mute', async ctx => {
    const userId = ctx.message?.reply_to_message?.from?.id;
    if (!userId) return ctx.reply('Reply to a message to mute.');

    await ctx.restrictChatMember(
        userId,
        {
            can_send_messages: false,
            can_send_photos: false,
            can_send_videos: false,
        },
        {
            until_date: Math.floor(Date.now() / 1000) + 3600, // 1 hour
        }
    );
    await ctx.reply('User muted for 1 hour.');
});

Promoting to Admin

typescript
bot.command('promote', async ctx => {
    const userId = ctx.message?.reply_to_message?.from?.id;
    if (!userId) return;

    await ctx.promoteChatMember(userId, {
        can_delete_messages: true,
        can_restrict_members: true,
        can_pin_messages: true,
    });
    await ctx.reply('User promoted to admin.');
});

Chat Information

typescript
// Get chat details
bot.command('info', async ctx => {
    const chat = await ctx.getChat();
    const count = await ctx.getChatMembersCount();
    await ctx.reply(`Chat: ${chat.title}\nMembers: ${count}`);
});

// Check member status
bot.command('status', async ctx => {
    const userId = ctx.message?.reply_to_message?.from?.id || ctx.from?.id || 0;
    const member = await ctx.getChatMember(userId);
    await ctx.reply(`Status: ${member.status}`);
});
typescript
bot.command('invite', async ctx => {
    const link = await ctx.createChatInviteLink({
        name: 'Promo Link',
        expire_date: Math.floor(Date.now() / 1000) + 86400, // 24 hours
        member_limit: 100,
    });
    await ctx.reply(`Invite: ${link.invite_link}`);
});

Setting Permissions

typescript
bot.command('lockdown', async ctx => {
    await ctx.setChatPermissions({
        can_send_messages: false,
        can_send_photos: false,
        can_send_videos: false,
    });
    await ctx.reply('Chat locked down — only admins can post.');
});

All Admin Methods

MethodAPIDescription
ctx.banChatMember(userId, extra?)banChatMemberBan a user
ctx.unbanChatMember(userId, extra?)unbanChatMemberUnban a user
ctx.restrictChatMember(userId, perms, extra?)restrictChatMemberRestrict user permissions
ctx.promoteChatMember(userId, perms?)promoteChatMemberPromote to admin
ctx.setChatPermissions(perms, extra?)setChatPermissionsSet default chat permissions
ctx.getChatMember(userId)getChatMemberGet member info and status
ctx.getChatMembersCount()getChatMemberCountGet total member count
ctx.getChat()getChatGet full chat information
ctx.createChatInviteLink(extra?)createChatInviteLinkCreate invite link
ctx.exportChatInviteLink()exportChatInviteLinkGet primary invite link
ctx.approveChatJoinRequest(userId)approveChatJoinRequestApprove join request
ctx.declineChatJoinRequest(userId)declineChatJoinRequestDecline join request
ctx.leaveChat()leaveChatBot leaves the chat
ctx.pinChatMessage(messageId?, notify?)pinChatMessagePin a message
ctx.unpinChatMessage(messageId?)unpinChatMessageUnpin a message

Released under the ISC License.