How to send message to my channel using telethon

Kurina11

I'm trying to make my python script send messages to my private channel but I get this error.

telethon.errors.rpcerrorlist.ChatWriteForbiddenError: You can't write in this chat (caused by SendMessageRequest)

I'm only admin in that channel and here is code what I use for sending messages, when I try to send message to myself it works fine..

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

Do I need to change something to have admin rights on my script or where is the problem? I'll be glad for every answer. Gimme some good sample code guys :D this is really big problem for me now.

Purya

At first test that you can send message to another channel or user. if you can't you must share all the code.

then make sure that account you are using at this case is admin in the channel. it's impossible you getting this error if the account is admin. also check admin rights and make sure post message is enable.

enter image description here

between, use channel username or channel numeric id instead 'my channel name'. channel numeric id starts with -100 like -1001212229355. you better to use numeric id. to find this just forward one of your channel messages to https://t.me/userinfobot.

await client.send_message(entity='my channel name', message=message)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I send messages to my private telegram channel with Telethon?

How to get channel/chat/user name of forwarded message using Telethon?

How to get new message received from the telegram channel using telethon

How to send message followed by start to a bot by link using telethon?

How to send a message in the Slack channel using Flutter?

Send message with backward timestamp using telethon in Telegram?

How can I get my bot to send a message to another channel?

How to check Send Message permission of bot in my Discord Channel?

How to edit message in Telegram using Telethon?

How to monitor Telegram message reactions using Telethon?

How to send a message to a specific channel

How to send message to tagged channel?

How i can delete message after send in telethon?

How can I receive messages from a channel using the Telethon library?

How to get entity of a channel using Telethon bot API?

How to get all users in a telegram channel using telethon?

How can I get updates for a specific private channel using telethon?

Send message to channel at random using lists

I'm using JDA 4.4.0_352 and my Discord Bot is unable to send message in the channel

hey guys, i'm using slack for alert message to send invoice data from my api To slack channel

How to send a error message in a specific channel

How to send a message to a Channel on all Servers

How do i send a message in a specific channel when my bot start

How can I make my bot send a message to a Telegram channel, and what is the significance of adding -100 in front of the channel ID?

How to broadcast message using channel

How can I send an image with a caption using Telethon in python?

How to send messages scraped from telegram channels using Telethon bot?

How i can add my contact in my channel with telethon API python

How to send hyperlink in message body using javamail API in my app?