提问人:Sandy 提问时间:5/30/2022 更新时间:5/31/2022 访问量:3020
Telethon:加入聊天/频道,但不知道它是公共频道还是聊天
Telethon: Join a Chat/Channel without to know if it's a public channel or a chat
问:
我正在使用以下功能加入群组(私人聊天)或公共频道:
def joinChannel(channel_id):
with TelegramClient(session_name, api_id, api_hash) as client:
result = client(functions.channels.JoinChannelRequest(
channel=channel_id
))
print(result.stringify())
def joinGroup(group_id):
with TelegramClient(session_name, api_id, api_hash) as client:
# remove "+"
updates = client(functions.messages.ImportChatInviteRequest(str(group_id)))
print(updates.chats[0].id)
那么,如何解析邀请链接以知道要调用的方法呢?
答:
0赞
Aref Solaimany
5/31/2022
#1
将您的方法更改为:
def joinChannel(channel_id):
with TelegramClient(session_name, api_id, api_hash) as client:
result = client(functions.channels.JoinChannelRequest(
channel=channel_id
))
return (result.stringify())
并使用以下代码:
Result = joinChannel(channel_id)
if( Result == "ChannelInvalidError"){
joinGroup(group_id)
}else{
print (Result)
}
评论
0赞
Mohammad Zarchi
4/11/2023
你有使用用户名加入频道的解决方案吗?
评论