假设我已加入TELEGRAM群组...
我只是一个典型的群组成员(因此无法在群组中使用任何机器人..?),所以我无法找出获取群组ID的方法。
最新更新
只需将您的频道信息简单地转发到此机器人:https://telegram.me/getidsbot
更新
1:前往https://web.telegram.org
2:进入您的群组并找到群组链接(https://web.telegram.org/#/im?p=g154513121)
3:复制 g 后面的数字,并在数字前加上一个短横线“-” -154513121
4:向群组发送您的消息
bot.sendMessage(-154513121, "你好")
我已经测试过了,可以正常工作。
Node.js:
请尝试使用TelegramBot#getChat()函数。
bot.getChat("@channelusername").then(function(chat) {
// 'chat' is a Chat object
console.log(chat.id);
});
请查看API getChat()方法和Chat对象。
希望对你有所帮助。
../im?p=@GroupSlugName
- T.Todua有一个非官方的Plus Messenger客户端适用于安卓用户,你可以在群组/频道信息中看到ID。
超级群组和频道会显示像1068773197
这样的数字,对于机器人而言是-1001068773197
(带有-100
前缀)。
如果你只想获取频道/用户ID,请将消息转发给@RawDataBot。
有很多方法可以做到这一点。
最简单的方法:下载Plus Messenger,它是Telegram的一个分支。它在该频道的“关于”页面中显示每个频道的ID。
https://play.google.com/store/apps/details?id=org.telegram.plus&hl=en
感谢@Sean:
超级群组和频道看起来像1068773197,对于机器人来说是-1001068773197(带有-100前缀)。
通过代码:
如果您是某个群组的成员,每当该群组有任何活动时,您都应该收到来自该群组的 更新
。更新将包含一个聊天
列表元素,您可以从中获取一个频道
,其中包含以下相关字段:
id: group_id,
title: "the_group_title",
username: "group_username"
getUpdates
,但普通用户呢?我在那些群组中没有机器人。 - T.Todua根据我的经验,目前有两个流行的库:
python-Telethon --->Telegram Client Library(uses api_id,api_hash)
python-Telegram-bot ---->Telegram Bot (uses api token)
有许多方法可以获取用户ID、组ID和频道ID。 使用Telethon客户端库可获取这些ID。
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))
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
经过数小时的努力,我成功使用CuteGram应用程序找到了GROUPS的ID。
在该应用程序中打开群组,并点击“COPY”图标,这将打开一个文件夹,在地址栏中您将看到ID。
@jsondumpbot
或在Telegram上搜索JSON Dump Bot。这是你转发的频道/群组
邀请您的机器人加入您的群组
并使用您的机器人发送 /myid 命令
然后使用 GetUpdates API,您将获得您的群组ID