使用Telethon能否将消息转发至Telegram群组话题?
解决Telethon向群组话题发消息/转发消息的报错问题
问题分析
你尝试用reply_to参数指定群组话题ID发送消息时触发了TypeError: ord() expected a character, but string of length 2 found错误,核心原因是用错了参数:reply_to是用来指定回复某条具体消息的ID,而非话题ID。
正确实现方式
Telethon中指定群组话题的正确参数是message_thread_id,发送消息和转发消息场景都适用:
发送消息到话题
await client.send_message( destination_id, message, message_thread_id=destination_topic_id )
转发消息到话题
await client.forward_messages( destination_id, messages_to_forward, message_thread_id=destination_topic_id )
错误原因说明
你之前的代码把话题ID传给了reply_to,这个参数预期接收单条消息的整数ID,当传入不符合要求的内容时,内部文本处理逻辑出现类型不匹配,从而抛出ord()相关错误。
内容的提问来源于stack exchange,提问作者jackwalton
相关产品推荐
相关产品推荐

