Если кто-то работает с ботами в ТГ, то вот простой код для бота, который в ответ на "Start" будет отправлять Вам ваш "Чат ID" и @:
И для любителей aiogram:
import asyncio
from telegram import Update
from telegram.ext import Application, CommandHandler, ContextTypes
BOT_TOKEN = 'VASH_TOKEN_BOT'
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
chat_id = update.effective_chat.id
username = update.effective_user.username or "Нет имени пользователя"
await update.message.reply_text(f'Chat ID: {chat_id}\nUsername: @{username}')
def main():
application = Application.builder().token(BOT_TOKEN).build()
application.add_handler(CommandHandler('start', start))
loop = asyncio.get_event_loop()
loop.run_until_complete(application.run_polling())
if __name__ == '__main__':
main()
И для любителей aiogram:
from aiogram import Bot, Dispatcher, types
from aiogram.types import Message
from aiogram import F
import asyncio
BOT_TOKEN = ''
async def start_handler(message: Message):
chat_id = message.chat.id
username = message.from_user.username or "Нет имени пользователя"
await message.reply(f'Chat ID: {chat_id}\nUsername: @{username}')
async def main():
bot = Bot(token=BOT_TOKEN)
dp = Dispatcher()
dp.message.register(start_handler, F.text.startswith('/start'))
try:
await dp.start_polling(bot)
finally:
await bot.session.close()
if __name__ == '__main__':
asyncio.run(main())