我尝试使用 ImportChatInviteRequest 就像文档中所说的那样,但无法加入公共或私人频道。使用 JoinChannelRequest 我只能加入公共频道。有什么办法让我失踪吗?
CHANNEL = 'https://t.me/TEST_INVITE'
await client(JoinChannelRequest(CHANNEL))
print(f'Successfully joined channel {CHANNEL}')
使用不同的 CHANNEL 变量结构尝试此代码
await client(JoinChannelRequest(CHANNEL))
print(f'Successfully joined channel {CHANNEL}')
比如
CHANNEL = 'https://t.me/TEST_INVITE'
# and
CHANNEL = 'TEST_INVITE'
邀请链接:如果您有邀请链接,您确实应该使用 ImportChatInviteRequest 加入它。 访问哈希:或者,如果您有私有频道的访问哈希,则可以将其与 JoinChannelRequest 一起使用。
from telethon.sync import TelegramClient
from telethon.tl.functions.channels import JoinChannelRequest, ImportChatInviteRequest
# Your Telegram API credentials
api_id = 'your_api_id'
api_hash = 'your_api_hash'
phone_number = 'your_phone_number'
# Initialize the client
client = TelegramClient(phone_number, api_id, api_hash)
async def join_channel():
# Connect to the Telegram servers
await client.start()
# Define the invite link
invite_link = 'https://t.me/TEST_INVITE'
try:
# Join the channel using the invite link
result = await client(ImportChatInviteRequest(invite_link))
print(f'Successfully joined channel: {result.chats[0].title}')
except Exception as e:
print(f'Failed to join channel: {e}')
# Run the function
with client:
client.loop.run_until_complete(join_channel())