GramJS

channels.JoinChannel

Join 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.JoinChannel({
      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.JoinChannel({
      channel: "username",
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
channelInputChannelChannel/supergroup to join

Result

Updates

Possible errors

CodeTypeDescription
400CHANNELS_TOO_MUCHYou have joined too many channels/supergroups
400CHANNEL_INVALIDThe provided channel is invalid
400CHANNEL_PRIVATEYou haven't joined this channel/supergroup
400INVITE_HASH_EMPTYThe invite hash is empty
400INVITE_HASH_EXPIREDThe invite link has expired
400INVITE_HASH_INVALIDThe invite hash is invalid
400MSG_ID_INVALIDInvalid message ID provided
400PEER_ID_INVALIDThe provided peer id is invalid
400USERS_TOO_MUCHThe maximum number of users has been exceeded (to create a chat, for example)
400USER_ALREADY_PARTICIPANTThe user is already in the group
400USER_CHANNELS_TOO_MUCHOne of the users you tried to add is already in too many channels/supergroups

Can bots use this method?

No