我想将机器人添加到Telegram组,但不是通过手动方法:
而是通过API,比如:
我没能让它工作。我试过了。
https://telegram.me/mybotname?startgroup=mygroupname,
或mygroupname中的/start@mybotname
。这两种方式都不会将我的机器人添加到电报组中。
我需要通过API将机器人添加到电报组的原因是,我有十几个这样的电报组要添加这个新机器人。
2岁的问题,但这对我有帮助:
使用用户API(不是机器人API)和message. addChatUser方法。
它不仅适用于添加用户,也适用于机器人。
https://core.telegram.org/method/messages.addChatUser
获取bot_id使用https://api.telegram.org/bot{TOKEN}/getMe(使用来自机器人父亲的令牌)
这是python上的代码示例:
from telethon.sync import TelegramClient
from telethon.sessions import StringSession
from telethon.tl.functions.messages import AddChatUserRequest
session = StringSession("") # You should put your string session here
client = TelegramClient(session, api_id, api_hash)
async def run():
await client.connect() # This assumes you have already authenticated
result = await client(AddChatUserRequest(
chat_id=chat_id,
user_id=bot_id,
fwd_limit=43,
))
print(result) # prints the result
with client:
client.loop.run_until_complete(run())