Telethon SendReactionRequest:预期是 TLObject,但发现了其他内容

问题描述 投票:0回答:1

这代表 Telethon 请求在公共频道的帖子上发送反应。运行代码时,当代码尝试运行此“SendReactionRequest”时,我遇到了一些错误,它们捕获了 TLC 对象的错误

import asyncio
from telethon.sync import TelegramClient
from telethon.tl.functions.channels import GetFullChannelRequest
from telethon.tl.functions.messages import SendReactionRequest

async def send_reaction(client, chat_id, message_id):
    try:
        await client(SendReactionRequest(
            peer=chat_id,
            msg_id=message_id,
            big=True,
            add_to_recent=True,
            reaction='👍'
        ))
        print('Reaction sent successfully')
    except Exception as e:
        print("Error sending reaction:", str(e))

async def main(phone):
    async with TelegramClient(f'sessions/{phone}', APIID, 'HashXXXX') as client:
        if not await client.is_user_authorized():
            print(f'{phone} needs to be authenticated by OTP')
            return

        chat_id = 'ViewTestChannel12'
        message_id = 9

        await send_reaction(client, chat_id, message_id)

with open('phone.csv', 'r') as file:
    phones = file.read().splitlines()

async def run_main():
    for phone in phones:
        await main(phone)

asyncio.run(run_main())
python telegram channel telethon tlc
1个回答
0
投票

原始 API(当您使用

client(SomeRequest(...))
时)可能会因库的次要版本而发生变化。在这种情况下,旧版本的请求仅使用表情符号字符串,但现在(从 v1.29 开始)是
Reaction
,如您在
SendReactionRequest
:

中看到的
result = client(functions.messages.SendReactionRequest(
    peer=chat_id,
    msg_id=message_id,
    big=True,
    add_to_recent=True,
    reaction=[types.ReactionEmoji(
        emoticon='👍'
    )]
))

(如果复制粘贴表情符号不起作用,请尝试使用正确的 unicode 转义序列。)

© www.soinside.com 2019 - 2024. All rights reserved.