电视节目。将频道设为私有
Telethon. Make channel private
如何使用 Telethon 将频道设为私有?我可以 public 为他们分配用户名:
from telethon import TelegramClient, utils, functions
from telethon.tl.types import InputChannel
channel: InputChannel = utils.get_input_channel(await client.get_input_entity('https://t.me/joinchat/xxxxx'))
print(await client(functions.channels.UpdateUsernameRequest(channel=channel, username='fuckdadasfa21')))
但是我怎样才能让他们恢复隐私呢?我在官方文档中没有找到这个信息。
您可以只传递一个空字符串作为新用户名以将其设为私有。并使用 ExportChatInviteRequest
获得邀请 link。
这是一个示例脚本:
from telethon import TelegramClient, utils, functions
API_ID = ...
API_HASH = " ... "
client = TelegramClient('session', api_id=API_ID, api_hash=API_HASH)
async def makeChannelPublic(channel_handler, new_handler):
return await client(functions.channels.UpdateUsernameRequest(channel=channel_handler, username=new_handler))
async def makeChannelPrivate(channel_handler):
await client(functions.channels.UpdateUsernameRequest(channel=channel_handler, username=''))
return await client(functions.messages.ExportChatInviteRequest(
peer=channel_handler
))
with client:
# client.loop.run_until_complete(makeChannelPublic('https://t.me/joinchat/ .... ', 'publicusername'))
invite_link = client.loop.run_until_complete(
makeChannelPrivate('publicusername'))
print(invite_link.link) # invite link for the private channel
如何使用 Telethon 将频道设为私有?我可以 public 为他们分配用户名:
from telethon import TelegramClient, utils, functions
from telethon.tl.types import InputChannel
channel: InputChannel = utils.get_input_channel(await client.get_input_entity('https://t.me/joinchat/xxxxx'))
print(await client(functions.channels.UpdateUsernameRequest(channel=channel, username='fuckdadasfa21')))
但是我怎样才能让他们恢复隐私呢?我在官方文档中没有找到这个信息。
您可以只传递一个空字符串作为新用户名以将其设为私有。并使用 ExportChatInviteRequest
获得邀请 link。
这是一个示例脚本:
from telethon import TelegramClient, utils, functions
API_ID = ...
API_HASH = " ... "
client = TelegramClient('session', api_id=API_ID, api_hash=API_HASH)
async def makeChannelPublic(channel_handler, new_handler):
return await client(functions.channels.UpdateUsernameRequest(channel=channel_handler, username=new_handler))
async def makeChannelPrivate(channel_handler):
await client(functions.channels.UpdateUsernameRequest(channel=channel_handler, username=''))
return await client(functions.messages.ExportChatInviteRequest(
peer=channel_handler
))
with client:
# client.loop.run_until_complete(makeChannelPublic('https://t.me/joinchat/ .... ', 'publicusername'))
invite_link = client.loop.run_until_complete(
makeChannelPrivate('publicusername'))
print(invite_link.link) # invite link for the private channel