channels.CreateChannel
Create a supergroup/channel.
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.CreateChannel({
title: "My very normal title",
about: "some string here",
megagroup: true,
forImport: true,
geoPoint: new Api.InputGeoPoint({
lat: 8.24,
long: 8.24,
accuracyRadius: 43,
}),
address: "some string here",
})
);
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.CreateChannel({
title: "My very normal title",
about: "some string here",
megagroup: true,
forImport: true,
geoPoint: new Api.InputGeoPoint({
lat: 8.24,
long: 8.24,
accuracyRadius: 43,
}),
address: "some string here",
})
);
console.log(result); // prints the result
})();
Parameters
Name | Type | Description |
---|---|---|
flags | # | Flags, see TL conditional fields |
broadcast | flags.0?true | Whether to create a channel |
megagroup | flags.1?true | Whether to create a supergroup |
forImport | flags.3?true | Whether the supergroup is being created to import messages from a foreign chat service using messages.initHistoryImport |
title | string | Channel title |
about | string | Channel description |
geoPoint | flags.2?InputGeoPoint | Geogroup location |
address | flags.2?string | Geogroup address |
Result
Possible errors
Code | Type | Description |
---|---|---|
400 | CHANNELS_ADMIN_LOCATED_TOO_MUCH | The user has reached the limit of public geogroups. |
400 | CHANNELS_TOO_MUCH | You have joined too many channels/supergroups. |
400 | CHAT_ABOUT_TOO_LONG | Chat about too long. |
400 | CHAT_TITLE_EMPTY | No chat title provided. |
406 | USER_RESTRICTED | You're spamreported, you can't create channels or chats. |
Can bots use this method?
No
Related pages
Channels, supergroups, gigagroups and basic groups
How to handle channels, supergroups, gigagroups, basic groups, and what's the difference between them.
messages.initHistoryImport
Import chat history from a foreign chat app into a specific Telegram chat, click here for more info about imported chats ยป.