问题描述
这是我的程序代码:
chn = 'https://t.me/Crypto_Claimer_Bot?start=1003997020'
channel_entity = client.get_entity(chn)
print('LOGIN DENGAN @'+myself.username+'\n')
client.send_message(entity=channel_entity,message='/start')
运行程序时,会出现如下错误:
Traceback (most recent call last):
File "ulang.py",line 55,in <module>
channel_entity = client.get_entity(chn)
File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/telethon/sync.py",line 39,in syncified
return loop.run_until_complete(coro)
File "/data/data/com.termux/files/usr/lib/python3.8/asyncio/base_events.py",line 616,in run_until_complete
return future.result()
File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/telethon/client/users.py",line 311,in get_entity
result.append(await self._get_entity_from_string(x))
File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/telethon/client/users.py",line 546,in _get_entity_from_string
raise ValueError(
ValueError: Cannot find any entity corresponding to "https://t.me/Crypto_Claimer_Bot?start=1003997020"
解决方法
首先,您拥有的链接不是entity
。您应该可以将?
之前的链接部分用作实体。因此,最好将链接分为两部分。
link = 'https://t.me/Crypto_Claimer_Bot?start=1003997020'
bot_link,refereal = link.split('?')
message = f'/start {refereal.split('=')[1]}'
await client.send_message(bot_link,message)