获取 TELEGRAM Channel/Group ID

Get TELEGRAM Channel/Group ID

比方说,我加入了TELEGRAM组...

我只是 GROUP 的典型成员(因此,不能在那里使用任何机器人..?)所以,我无法找到获取 GROUP ID 的方法。

应该可以使用 tg-messenger-cli 获得:https://github.com/vysheng/tg我还没有时间尝试,但朋友已经为他的女儿发送了一些自动消息。应该是相当通用的。

有很多方法可以做到这一点。

最简单的一个:下载plus messenger,它是telegram的一个分支。它在该频道的关于页面中显示每个频道的 ID。

https://play.google.com/store/apps/details?id=org.telegram.plus&hl=en

感谢@Sean:

Supergroup 和 Channel 看起来像 1068773197,对于机器人来说是 -1001068773197(前缀为 -100)。


以上方法适用于频道,群组可以使用此方法:

只需将该聊天中的一条消息转发给@RawDataBot。它会用包含 chatid 的 json 数据回复你。

unofficl Plus Messenger 客户端供Android 用户使用,您可以在group/channel 信息中查看ID。

超级组和频道看起来像 1068773197,对于机器人来说是 -1001068773197(带有 -100 前缀)。

如果您只想获取channel/user ID,请转发消息至@RawDataBot

通过代码:

如果您是某个群组的成员,那么只要该群组有 activity,您就应该收到来自该群组的 updates。更新将包含一个 chats 列表元素,您可以从中获得一个 Channel,其中包含以下相关字段:

id: group_id, 
title: "the_group_title", 
username: "group_username"

新更新
只需简单地将消息从您的频道转发到此机器人:(https://telegram.me/getidsbot)

更新
1: 转到 (https://web.telegram.org)
2: 转到你的 Gorup 并找到你的 link of Gorup(https://web.telegram.org/#/im?p=g154513121)
3:在g之后复制那个数字并在-154513121
之前放一个(-) 4:将您的消息发送给 Gorup bot.sendMessage(-154513121, "Hi")
我现在测试并像魅力一样工作

Node.js:
尝试使用 TelegramBot#getChat():

bot.getChat("@channelusername").then(function(chat) {
    // 'chat' is a Chat object
    console.log(chat.id);
});

参见 API getChat() method and Chat 对象。

希望对您有所帮助。

花了几个小时后,我能够使用 CuteGram 应用找到群组的 ID。

在那里打开组,然后单击"COPY"图标,打开一个文件夹,在地址中你会看到ID。

邀请您的机器人加入您的群组

并使用你的机器人发送短信 /myid

然后使用 GetUpdates api,你应该有你的组 ID

根据我的经验,有两个流行的库,

python-Telethon            --->Telegram Client Library(uses api_id,api_hash) 
python-Telegram-bot        ---->Telegram Bot (uses api token)

有很多方法可以获得 user_id ,group_id,channel_id 。 要获取这些 ID,请使用 Telethon 客户端库

from telethon import TelegramClient,sync
api_id="xxx" #get from telegram website
api_hash="yyy" #get from telegram website
client=TelegramClient(session_object,api_id,api_hash) 
client.start()
#To get the channel_id,group_id,user_id
for chat in client.get_dialogs():
    print('name:{0} ids:{1} is_user:{2} is_channel{3} is_group:{4}'.format(chat.name,chat.id,chat.is_user,chat.is_channel,chat.is_group))

就是这样,它将打印频道、组、用户的名称和ID。 此外,它将检查 id 是否属于频道或组或用户

一般来说,Channel id以负数开头(eg:-1001109500936)以(-100)开头 group id正常,以负数开头 用户 ID 以 positve

开头

另一种方法是使用 'plus messanger app' 查看所有组、频道、用户ID 干杯

另一个简单的方法,

client=TelegramClient(session,api_id,api_hash)
client.start()
destination_entity_name="Type User(may be bot) or group or channel name"
entity=client.get_entity(destination_entity_name)
print(entity.stringify()) #All paratmeters
print(entity.id)       #user(bot also considered as user) or group