python - 马拉松。如何创建公共(public)/私有(private) channel ?

标签 python python-3.x telegram telethon

如何使用 Telethon 创建公共(public)/私有(private) channel ?我在官方文档中没有找到这个信息。

最佳答案

您可以使用此过程来创建私有(private) channel (并通过为其分配用户名将其公开):

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))

关于python - 马拉松。如何创建公共(public)/私有(private) channel ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52160946/

相关文章:

python - 使用 python pandas 解析格式为 Year, Day, Hour, Min, Sec 的 CSV

python - 如何让我的 Discord 机器人每周日在 0 :00? 运行一个函数

python - 使用Python从数据库中提取

telegram - 如何获取 telegram 以显示我网站的信息卡

tcp - 如何从它的 TCP header 中检测 Telegram 协议(protocol)?

Python os.walk() 方法

python - pandas int 和 np.int64 中的奇怪 isinstance 行为

telegram - Telegram user_id 的长度可以是多少?

python - 将多个图形保存到一个多页 PDF 文档时出错

python - 如何在Python中将不同的时间序列图合并成二维图