проблема с telethon
Мне нужно добавить пользователя телеграмм в определенный канал. Код перед командой, которая непосредственно делает запрос на добавление пользователя в канал, работает. При отправке запроса вылазит исключение, которое говорит, что вы зашли, как бот, а бот не может делать такие запросы. В интернете ответа не нашел.
from telethon.sync import TelegramClient
from telethon import functions, types
from telethon.tl.functions.channels import InviteToChannelRequest
from telethon.tl.functions.contacts import ResolveUsernameRequest
from telethon.tl.types import InputPeerChannel ,InputPeerUser,InputUser
from telethon.tl.functions.channels import JoinChannelRequest
channel_name = "channel_name"
api_id = "#######" #security inf
api_hash = "############################" #security inf
client = TelegramClient('new_sec', api_id, api_hash)
client.start()
chann = client.get_entity(channel_name)
chan = InputPeerChannel(chann.id, chann.access_hash)
user = client.get_entity("username")
client(InviteToChannelRequest(channel=channel_name, users=[user]))
Ответы (1 шт):
Автор решения: Дмитрий Бовак
→ Ссылка
# For normal chats
from telethon.tl.functions.messages import AddChatUserRequest
# Note that ``user_to_add`` is NOT the name of the parameter.
# It's the user you want to add (``user_id=user_to_add``).
await client(AddChatUserRequest(
chat_id,
user_to_add,
fwd_limit=10 # Allow the user to see the 10 last messages
))
# For channels (which includes megagroups)
from telethon.tl.functions.channels import InviteToChannelRequest
await client(InviteToChannelRequest(
channel,
[users_to_add]
))