Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telethon. How to create a public/private channel?

How to create a public/private channel with Telethon? I did not find this information in the official documentation.

like image 713
strannik-j Avatar asked Sep 15 '25 07:09

strannik-j


1 Answers

you can use this procedure to create private channels(and also making them public by assigning username to them):

from telethon.tl.functions.channels import CreateChannelRequest, CheckUsernameRequest, UpdateUsernameRequest
from telethon.tl.types import InputChannel, InputPeerChannel
createdPrivateChannel = client(CreateChannelRequest("title","about",megagroup=False))

#if you want to make it public use the rest
newChannelID = createdPrivateChannel.__dict__["chats"][0].__dict__["id"]
newChannelAccessHash = createdPrivateChannel.__dict__["chats"][0].__dict__["access_hash"]
desiredPublicUsername = "myUsernameForPublicChannel"
checkUsernameResult = client(CheckUsernameRequest(InputPeerChannel(channel_id=newChannelID, access_hash=newChannelAccessHash), desiredPublicUsername))
if(checkUsernameResult==True):
    publicChannel = client(UpdateUsernameRequest(InputPeerChannel(channel_id=newChannelID, access_hash=newChannelAccessHash), desiredPublicUsername))
like image 74
tashakori Avatar answered Sep 17 '25 21:09

tashakori