转换为超级组时,电报聊天 ID 是否保持不变? [英] Do telegram chat IDs stay the same when converting to a supergroup?
问题描述
在 Telegram 上,每个群组都有一个 chat-id
,我的机器人会在将其添加到群组时保存该 ID.
如果一个群组的所有者将其转换为超级群组,该群组的 ID 会发生变化吗?如果是这样,我们如何为群组获取新的 chat-id
?
我在互联网上到处寻找这个都没有成功,所以我在这里要求自我回答以帮助人们在未来寻找这个,节省他们的时间反复试验.
在我自己测试之后,chat-id
在迁移到超级组时确实发生了变化.
但是我发现了以下方法,使用 python-telegram-bot
来更新您的聊天 ID:
def migchat(bot, update):oldchatid = update.message.migrate_from_chat_idnewchatid = update.message.chat.id# 根据需要处理这些值(例如更新数据库)dispatcher.add_handler(MessageHandler(Filters.status_update.migrate, migchat))
这使用
On Telegram, every group has a chat-id
that my bot saves whenever it is added to a group.
If an owner of a group converts it to a supergroup, will the ID of the group change? And if it does, how can we get the new chat-id
for the group?
I've looked for this all over the internet without success, so I'm asking here to self-answer to help people looking for this in the future, saving them the time trial and error took me.
After testing it out for myself, the chat-id
does change on migration to a supergroup.
However I found the following way, using python-telegram-bot
to keep your chat-ids updated:
def migchat(bot, update):
oldchatid = update.message.migrate_from_chat_id
newchatid = update.message.chat.id
# process those values as needed (e.g. update a database)
dispatcher.add_handler(MessageHandler(Filters.status_update.migrate, migchat))
This uses the Filters submodule to call migchat
whenever a chat is being migrated.
This is how the JSON response of the message from the /getUpdates
call looks like:
这篇关于转换为超级组时,电报聊天 ID 是否保持不变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!