Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Telethon错误:无法使用AddChatUserRequest()将用户添加到组中,聊天对象ID无效_Python 3.x_Telegram Bot_Telethon - Fatal编程技术网

Python 3.x Telethon错误:无法使用AddChatUserRequest()将用户添加到组中,聊天对象ID无效

Python 3.x Telethon错误:无法使用AddChatUserRequest()将用户添加到组中,聊天对象ID无效,python-3.x,telegram-bot,telethon,Python 3.x,Telegram Bot,Telethon,当我使用AddChatUserRequest将用户添加到组中时,我尝试使用telethon开发一个电报机器人 client(AddChatUserRequest(1168070860, user.id, fwd_limit=10)) 我遇到了错误: telethon.errors.rpcerrorlist.ChatidValidError:的对象ID无效 聊天。确保传递正确的类型,例如确保 该请求是为聊天(而非频道/扩频组)或 否则,请寻找另一个更适合的\n示例 对于megagroup和Add

当我使用AddChatUserRequest将用户添加到组中时,我尝试使用telethon开发一个电报机器人

client(AddChatUserRequest(1168070860, user.id, fwd_limit=10))
我遇到了错误:

telethon.errors.rpcerrorlist.ChatidValidError:的对象ID无效 聊天。确保传递正确的类型,例如确保 该请求是为聊天(而非频道/扩频组)或 否则,请寻找另一个更适合的\n示例 对于megagroup和AddChatUserRequest,它将失败,因为 超级组是通道。改为使用InviteToChannelRequest(由 AddChatUserRequest)

我使用这些代码来获取团队的信息:

chats = client(GetDialogsRequest(
             offset_date=None,
             offset_id=0,
             offset_peer=InputPeerEmpty(),
             limit=200,
             hash = 0
         )).chats

groups = []
for chat in chats:
    try:
        if chat.megagroup == True:
            groups.append(chat)
            print(chat.title,chat.id)
    except:
        continue
下面是我试图添加的用户组信息:

Channel(left=False, id=1168070860, banned_rights=None, title='ruby and his friends', version=0, verified=False, signatures=False, broadcast=False, participants_count=None, creator=True, has_geo=False, photo=ChatPhoto(dc_id=1, photo_small=FileLocationToBeDeprecated(local_id=270793, volume_id=806122192), photo_big=FileLocationToBeDeprecated(local_id=270795, volume_id=806122192)), username='lanlugroup', megagroup=True, restricted=False, default_banned_rights=ChatBannedRights(change_info=True, until_date=datetime.datetime(2038, 1, 19, 3, 14, 7, tzinfo=datetime.timezone.utc), send_inline=False, invite_users=False, pin_messages=True, send_media=False, send_gifs=False, send_games=False, embed_links=False, send_stickers=False, send_messages=False, view_messages=False, send_polls=False), restriction_reason=None, min=False, has_link=False, scam=False, date=datetime.datetime(2019, 4, 1, 12, 44, 47, tzinfo=datetime.timezone.utc), admin_rights=None, access_hash=-5901560198799322202)
我在AddChatUserRequest中使用id 1168070860作为聊天室id


(顺便说一句,我用普通用户的电话号码登录,而不是机器人)

改用InviteToChannelRequest。我的解决方案:

chat_id = "mychatid"
users = ['UserName']

response = client.invoke(ResolveUsernameRequest(chat_id))

target_group_entity = InputPeerChannel(response.chats[0].id, response.chats[0].access_hash)

try:
    res = client(InviteToChannelRequest(channel=target_group_entity, users=users ))
except Exception as e:
    print("spam protection: " + e.message + ": " + str(e))