Answer the question
In order to leave comments, you need to log in
How to send a message knowing the user id in Telegram?
I'm writing code that will catch new messages on a channel. And if there is a certain text, then it will write to a certain user. The layer in the form of a bot is not used, messages should be sent on behalf of my account with which the user has already had correspondence.
It gives an error when sending a message
Request caused struct.error: argument out of range: GetUsersRequest(id=[InputUse
r(user_id=5091977781, access_hash=0)])
from telethon import TelegramClient, events
import asyncio
api_id = [api_id]
api_hash = "[api_hash]"
channel = -1001379139877
client = TelegramClient('bot', api_id, api_hash)
@client.on(events.NewMessage(chats=channel))
async def my_event_handler(event):
if "Первый, кто напишет" in str(event.message.message):
await client.send_message(5091977781, "+")
client.start()
client.run_until_disconnected()
Answer the question
In order to leave comments, you need to log in
A simple googling quickly found the following
on stackowerflow :
from telethon import utils
real_id, peer_type = utils.resolve_id(-1001234567891)
print(real_id) # 1234567891
print(peer_type) # <class 'telethon.tl.types.PeerChannel'>
peer = peer_type(real_id)
print(peer) # PeerChannel(channel_id=1234567891)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question