async def number(message: types.Message):
num = message.get_args()
from pyrogram import Client
from pyrogram.raw.functions.contacts import ResolveUsername
BOT_TOKEN = "<токен бота>"
pyrogram_client = Client(
"bot",
api_id=6,
api_hash="eb06d4abfb49dc3eeb1aeb98ae0f581e",
bot_token=BOT_TOKEN,
app_version="7.7.2",
device_model="Lenovo Z6 Lite",
system_version="11 R"
)
def resolve_username_to_user_id(username: str) -> int | None:
with pyrogram_client:
r = pyrogram_client.invoke(ResolveUsername(username=username))
if r.users:
return r.users[0].id
return None
print(resolve_username_to_user_id("Tishka17"))
def resolve_username_to_channel_id(username: str) -> int | None:
with pyrogram_client:
r = pyrogram_client.invoke(ResolveUsername(username=username))
if r.chats:
return r.chats[0].id
return None
bot.restrict_chat_member(chat_id, user_id, can_send_messages=False)
from aiogram import types
from aiogram.utils.keyboard import InlineKeyboardBuilder
builder = InlineKeyboardBuilder()
# 1 вариант (в строку)
builder.row(
types.InlineKeyboardButton(text, callback_data),
types.InlineKeyboardButton(text, callback_data)
)
# ---
# 2 вариант (в строку)
builder.button(text, callback_data)
builder.button(text, callback_data)
# ---
# 1 вариант (в столбец)
builder.row(
types.InlineKeyboardButton(text, callback_data),
types.InlineKeyboardButton(text, callback_data),
width=1
)
# ---
# 2 вариант (в столбец)
builder.button(text, callback_data)
builder.button(text, callback_data)
builder.adjust(1)
# ---
kb = [
[
types.InlineKeyboardButton(text, callback_data),
types.InlineKeyboardButton(text, callback_data)
],
[
types.InlineKeyboardButton(text, callback_data)
]
]
keyboard = types.InlineKeyboardMarkup(inline_keyboard=kb)
bot.send_photo(message.chat.id, img = open('Ржомба.png','rb'), caption = Text)
with open('Ржомба.png','rb') as f:
bot.send_photo(message.chat.id, img = f, caption = Text)
message.from_user.id
message.from_user.first_name
message.from_user.last_name
message.from_user.username
import telebot
import requests
token = 'токен'
bot = telebot.TeleBot(token)
@bot.message_handler(content_types=['text'])
def repeat_all_message(message):
print(message.text)
bot.send_message(message.chat.id,message.text)
@bot.message_handler(content_types=["document", "video", "audio"])
def handle_files(message):
document_id = message.document.file_id
file_info = bot.get_file(document_id)
print(document_id) # Выводим file_id
print(f'http://api.telegram.org/file/bot{token}/{file_info.file_path}') # Выводим ссылку на файл
bot.send_message(message.chat.id, document_id) # Отправляем пользователю file_id
if __name__ == '__main__':
bot.polling(none_stop=True)