How can I join the telegram chat bot using the referral link?

2.7k Views Asked by At

And this is my program code:

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

When I run my program, there is an error like this:

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"

From this error, what should I change in my program code?

1

There are 1 best solutions below

0
On BEST ANSWER

First of all the link you have isn't an entity. You should be able to use as an entity the part of the link before the ?. So you better split the link into two parts.

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)