Telethon账号发送消息至部分群组被即时禁言3天的问题求助
问题:Telegram脚本在部分群组发送消息即被禁言3天
我编写的脚本用于向Telegram群组发送消息,在部分群组可正常运行,但在另一些群组中,账号仅尝试发送第一条消息就被即时禁言3天,返回Request SendMessageRequest相关群组信息,可排除消息本身为垃圾信息的可能。
我的代码
api_id = 123456789 api_hash = 'API_HASH' try: with TelegramClient('session', api_id, api_hash) as client: client.loop.run_until_complete(client.send_message('group', 'my_message')) sleep(10) except: client.disconnect() client.start() client.run_until_disconnected()
账号发送消息时的输出信息
Request SendMessageRequest(peer=InputPeerChannel(channel_id=123456789, access_hash=-123456789), message='my_message', no_webpage=False, silent=None, background=None, clear_draft=False, noforwards=None, update_stickersets_order=None, reply_to_msg_id=None, top_msg_id=None, random_id=6399888382386879515, reply_markup=None, entities=[], schedule_date=None, send_as=None) had missing message mapping Updates(updates=[UpdateReadChannelInbox(channel_id=123456789, max_id=16456611, still_unread_count=0, pts=22916302, folder_id=None), UpdateNewChannelMessage(message=MessageEmpty(id=16456611, peer_id=PeerChannel(channel_id=123456789)), pts=22916302, pts_count=0)], users=[], chats=[Channel(id=123456789, title='Channel', photo=ChatPhoto(photo_id=5918253080787401965, dc_id=4, has_video=False, stripped_thumb=b'\x01\x08\x08\xcf\x0c\xbeV07g\xad\x14QL\x0f'), date=datetime.datetime(2023, 5, 4, 12, 40, 22, tzinfo=datetime.timezone.utc), creator=False, left=False, broadcast=False, verified=True, megagroup=True, restricted=False, signatures=False, min=False, scam=False, has_link=False, has_geo=False, slowmode_enabled=True, call_active=False, call_not_empty=False, fake=False, gigagroup=False, noforwards=False, join_to_send=False, join_request=False, forum=False, access_hash=-123456789, username='channel', restriction_reason=[], admin_rights=None, banned_rights=ChatBannedRights(until_date=datetime.datetime(2023, 5, 5, 12, 40, 26, tzinfo=datetime.timezone.utc), view_messages=False, send_messages=False, send_media=True, send_stickers=True, send_gifs=True, send_games=True, send_inline=True, embed_links=True, send_polls=True, change_info=False, invite_users=True, pin_messages=False, manage_topics=False, send_photos=True, send_videos=True, send_roundvideos=True, send_audios=True, send_voices=True, send_docs=True, send_plain=False), default_banned_rights=ChatBannedRights(until_date=datetime.datetime(2038, 1, 19, 3, 14, 7, tzinfo=datetime.timezone.utc), view_messages=False, send_messages=False, send_media=True, send_stickers=True, send_gifs=True, send_games=True, send_inline=True, embed_links=True, send_polls=True, change_info=True, invite_users=True, pin_messages=True, manage_topics=True, send_photos=True, send_videos=True, send_roundvideos=True, send_audios=True, send_voices=True, send_docs=True, send_plain=False), participants_count=None, usernames=[])], date=datetime.datetime(2023, 5, 4, 12, 49, 43, tzinfo=datetime.timezone.utc), seq=0)
原因分析
- 群组反垃圾规则差异:部分高活跃度、经过官方验证的群组会配置更严格的自动审核机制,比如要求新成员加入一定时长(如24小时)后才能发言,或限制低权重账号的发言权限,触发后直接自动禁言。
- 脚本行为异常:你的代码存在逻辑冗余——
with TelegramClient块已经会自动管理连接,后续又调用client.start()和run_until_disconnected(),这种非人类的会话操作容易被Telegram风控系统判定为机器人行为。 - 账号权重不足:如果账号是新注册、很少手动使用(无互动、无历史发言),Telegram的风控模型会将其标记为高风险账号,在规则严格的群组中直接触发禁言。
解决办法
修复脚本逻辑:移除冗余代码,使用标准异步写法:
from telethon import TelegramClient import time import asyncio api_id = 123456789 api_hash = 'API_HASH' async def send_group_message(): async with TelegramClient('session', api_id, api_hash) as client: await client.send_message('group', 'my_message') time.sleep(10) if __name__ == '__main__': asyncio.run(send_group_message())提升账号权重:手动登录账号,在宽松的群组进行正常互动(发言、点赞、转发),养号1-2周,让账号具备正常用户的行为特征。
适配群组规则:提前查看目标群组的公开规则,确认是否有新成员发言限制,部分群组需要完成机器人验证或等待指定时长后才能发言,脚本执行前先满足这些条件。
添加精准异常捕获:不要使用空
except,捕获具体异常并输出细节,方便排查问题:try: # 你的发送逻辑 except Exception as e: print(f"错误详情: {e}") if client and client.is_connected(): await client.disconnect()模拟人类行为:将固定间隔改为随机时间(如3-10秒随机等待),避免短时间内向多个群组发送相同内容,降低被检测为机器人的概率。
内容的提问来源于stack exchange,提问作者Matt Klein
相关产品推荐
相关产品推荐

