[英]How to send message to my channel using telethon
我試圖讓我的 python 腳本向我的私人頻道發送消息,但我收到此錯誤。
telethon.errors.rpcerrorlist.ChatWriteForbiddenError:你不能在這個聊天中寫信(由SendMessageRequest引起)
我只是該頻道的管理員,這是我用於發送消息的代碼,當我嘗試向自己發送消息時,它工作正常..
from telethon import TelegramClient
from telethon.errors import SessionPasswordNeededError
api_id = 'my api id'
api_hash = 'my api hash'
phone = 'my number'
username = 'my username'
# Create the client and connect
client = TelegramClient(username, api_id, api_hash)
client.start()
print("Client Created")
# Ensure you're authorized
if not client.is_user_authorized():
client.send_code_request(phone)
try:
client.sign_in(phone, input('Enter the code: '))
except SessionPasswordNeededError:
client.sign_in(password=input('Password: '))
async def send_mess(message):
await client.send_message(entity='my channel name', message=message)
while True:
some other code
if last_message != new_message:
with client:
client.loop.run_until_complete(send_mess(message=new_message))
last_message = new_message
我是否需要更改某些內容才能對我的腳本擁有管理員權限,或者問題出在哪里? 我會為每一個答案感到高興。 給我一些好的示例代碼伙計們:D 這對我來說真的是個大問題。
首先測試您是否可以向另一個頻道或用戶發送消息。 如果不能,則必須共享所有代碼。
然后確保您在這種情況下使用的帳戶是頻道中的管理員。 如果帳戶是管理員,則不可能出現此錯誤。 還要檢查管理員權限並確保啟用發布消息。
之間,使用頻道用戶名或頻道數字 id 而不是“我的頻道名稱”。 頻道數字 id 以-100
開頭,如-1001212229355
。 你最好使用數字ID。 要找到這個,只需將您的頻道消息之一轉發到https://t.me/userinfobot 。
await client.send_message(entity='my channel name', message=message)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.