Skip to content

Instantly share code, notes, and snippets.

@mraaroncruz
Last active July 9, 2024 03:13
Show Gist options
  • Save mraaroncruz/e76d19f7d61d59419002db54030ebe35 to your computer and use it in GitHub Desktop.
Save mraaroncruz/e76d19f7d61d59419002db54030ebe35 to your computer and use it in GitHub Desktop.
Get the Telegram channel ID

To get the channel id

  1. Create your bot with botfather
  2. Make you bot an admin of your channel

Simplest way (via @anhtuank7c)

Go to Telegram web and open a channel, get the ID from -[channel id] from hash in the path

https://web.telegram.org/k/#-9999999999999

-9999999999999 is the channel ID.

Link to suggestion

(DEPRECATED) New improved next steps

  1. Go to https://web.telegram.org
  2. Click on your channel
  3. Look at the URL and find the part that looks like c12112121212_17878787878787878
  4. Remove the underscore and after c12112121212
  5. Remove the prefixed letter 12112121212
  6. Prefix with a -100 so -10012112121212
  7. That's your channel id.

Old yucky next steps

  1. Make your channel public
  2. Create a public link
  3. Send a message from console to @[your_public_link_text]
  4. Copy chat id from response in console as the channel id
@myfingerhurt
Copy link

Just right click on channel post and select Copy Post Link, you will get something looks like to this
https://t.me/c/123456789/137

Then do -100 + 123456789 = -100123456789 is your Channel id.

image

@ImGegio95
Copy link

the solution doesn't work now. How can I find chat_id now?

@wonbinbk
Copy link

wonbinbk commented Feb 2, 2023

Thanks everyone, from this thread, I found 2 ways that work:

  1. Using web.telegram.org, and click on the channel, the URL will be something like: https://web.telegram.org/z/#-1782626220, the channel id is -1001782626220
  2. Forward a message from that channel to @username_to_id_bot, it will reply with the channel id.

@lifeeric
Copy link

lifeeric commented Feb 15, 2023

https://stackoverflow.com/questions/33858927/how-to-obtain-the-chat-id-of-a-private-telegram-channel/75456341#75456341

from telethon.sync import TelegramClient, events
client = TelegramClient("bot", API_ID, API_HASH)


channel_name = "channel username"
channel = client.get_entity(channel_name)
print(f'👉 Channel ID: {channel.id}')

client.start()
client.run_until_disconnected()

@anurag210
Copy link

Well I’ve channel id but how can I find it’s channel joining link to join

@supercrazysam
Copy link

Remember to make your bot admin in your channel, otherwise none of this shit above will work

@ArgX11
Copy link

ArgX11 commented Sep 30, 2023

How to send a DM to someone using Telegram Chat ID?
If someone's Username is John then the chat URL will be https://t.me/John
So, if someone's Chat ID is 12345 then what will be the Telegram chat URL?

@NabilHunt
Copy link

When I tried this few days ago there seems to be some changes:
link of the channel for ex: https://web.telegram.org/a/#-1001859733654

With the channel ID being what comes after "#"

@ErShakirAnsari
Copy link

much easier way .. forward a message from that channel to this @JsonDumpBot bot image can voila there's your ID

thanks

@anhtuank7c
Copy link

@crystalbit I found an alternative way in the meantime.

1. Go to https://web.telegram.org

2. Click on your channel

3. Look at the URL and find the part that looks like `c12112121212_17878787878787878`

4. Remove the underscore and after `c12112121212`

5. Remove the prefixed letter `12112121212`

6. Prefix with a `-100` so `-10012112121212`

7. That's your channel id.

Soooo stupid, but it is very quick and it works.

I just need to go to Telegram web and open a channel, id from -number

https://web.telegram.org/k/#-9999999999999

-9999999999999 is the channel id.

@mraaroncruz
Copy link
Author

Cool, looks like they updated their webapp. I'll update the original. Thanks for an actually useful new way @anhtuank7c

@kiarashjv
Copy link

kiarashjv commented Mar 19, 2024

The solution I used is to forward a message from my channel to @get_id_bot and it returns the id. Beside that, you could set a log in your bot and forward a message from private channel to it and in terminal you could see the id. The web telegram solution worked too but I think @get_id_bot is easier and the log method is safer if you want to keep your chat id private for any reason.

@anhtuank7c
Copy link

@kiarashjv I agreed with you about use @get_id_bot is convenient but I don't think web telegram expose your channel id so it still safe.

@mraaroncruz
Copy link
Author

while @get_id_bot exposes the channel ID to a random bot

@anhtuank7c
Copy link

@mraaroncruz you got the point 😎

@kiarashjv
Copy link

kiarashjv commented Mar 20, 2024

@mraaroncruz yeah, as I said it depends on you want to keep your ID private or not 😅

in total I think forwarding a message to your own bot is better because as I understand the method of extracting ID from web might change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment