**,python,api,telegram,message,script"/>

首页 > 解决方案 > Telegram 通过 API 和 Python 向其他组发送消息错误:****

问题描述

我需要帮助解决以下问题。我正在尝试编写一个脚本,将广告发送到我所属的多个 Telegram 组。这些组是为广告而制作的,我可以向这些组发送消息。

每次我运行脚本时,我都会收到以下错误:

<class 'telethon.errors.rpcerrorlist.ChatWriteForbiddenError'>

那是我的代码:

import sys
from telethon import TelegramClient
import time
import datetime 
starttime=time.time()

#Unsere API_ID und API_Hash

api_id=******
api_hash='******************'

TestGroup=['Name of Group']

textgroups= 'Thats the Text'

failcount=0,

while True:

  with TelegramClient('anon', api_id, api_hash) as client:

    for x in TestGroup:

      try:

        client.loop.run_until_complete(client.send_message(x, textgroups))

      except:

        print(x, sys.exc_info()[0])

        failcount +=1

  print(datetime.datetime.now(), str(failcount/len(groups)*100)+ '%')

  time.sleep(120)

标签: pythonapitelegrammessagescript

解决方案


推荐阅读