GramJS

channels.LeaveChannel

Leave a channel/supergroup

Example

const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result = await client.invoke(
    new Api.channels.LeaveChannel({
      channel: "username",
    })
  );
  console.log(result); // prints the result
})();
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result: Api.Updates = await client.invoke(
    new Api.channels.LeaveChannel({
      channel: "username",
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
channelInputChannelChannel/supergroup to leave

Result

Updates

Possible errors

CodeTypeDescription
400CHANNEL_INVALIDThe provided channel is invalid.
400CHANNEL_PRIVATEYou haven't joined this channel/supergroup.
403CHANNEL_PUBLIC_GROUP_NAchannel/supergroup not available.
400MSG_ID_INVALIDInvalid message ID provided.
400USER_BANNED_IN_CHANNELYou're banned from sending messages in supergroups/channels.
400USER_CREATORYou can't leave this channel, because you're its creator.
400USER_NOT_PARTICIPANTYou're not a member of this supergroup/channel.

Can bots use this method?

Yes

Channels, supergroups, gigagroups and basic groups

How to handle channels, supergroups, gigagroups, basic groups, and what's the difference between them.