Answer the question
In order to leave comments, you need to log in
How to fix send_message() got an unexpected keyword argument 'send_as' error?
I wrote a code for telegrams, it gives an error, how can I fix it? I am new to python
from telethon import TelegramClient, sync, events
from telethon.tl.types import PeerUser, PeerChat, PeerChannel, InputPeerChat
from telethon.tl.functions.messages import SendMessageRequest, GetHistoryRequest
from telethon.tl.functions.channels import JoinChannelRequest, LeaveChannelRequest
from telethon.errors import PhoneNumberBannedError, MsgIdInvalidError, ChannelPrivateError, UserDeactivatedBanError, \
FloodWaitError
import asyncio
import random
api_id = id
api_hash = 'hash'
client = TelegramClient('session_name', api_id, api_hash)
client.start()
async def leave_comment(client, event):
sleep = random.randint(0, 0) * 60
print("Спим " + str(sleep))
await asyncio.sleep(sleep)
i = random.randint(0, 1)
fraza = {"Это работает??"}
message = random.choice(list(fraza))
try:
await client.send_message(event.message.peer_id.channel_id, message=message, comment_to=event.message.id, send_as=
await client.get_input_entity("https://t.me/url"))
except ChannelPrivateError:
my_channel = await client.get_entity(PeerChannel(event.message.peer_id.channel_id))
print("Вас заблокировано на канале - " + name)
await client(LeaveChannelRequest(my_channel))
print(message)
@client.on(events.NewMessage(func=lambda e: e.is_channel))
async def handler(event):
if event.message.fwd_from is None and not (event.message.replies is None):
print("Вышел пост")
loop = asyncio.get_event_loop()
loop.create_task(leave_comment(client, event))
client.run_until_disconnected()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question