aiogram / aiogram/bot

Telegram bot future

Đang mở
#32 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
invalid
Ngôn ngữ chính
Python
Star
282
Fork
58
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import ApplicationBuilder, CommandHandler, CallbackQueryHandler, ContextTypes
import logging

BOT_TOKEN = "7699211626:AAEE0rLHWFzafG_jVlzGfOn9-QTbYooXvkE"
CHANNEL_USERNAME = "pixelverse_hd"

logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO
)

async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
keyboard = [
[InlineKeyboardButton("✅ Join Channel", url=f"https://t.me/{CHANNEL_USERNAME}")],
[InlineKeyboardButton("🔁 Verify", callback_data="verify")]
]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(
"Welcome! To use this bot, please join our channel first and verify.",
reply_markup=reply_markup
)

async def button_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
query = update.callback_query
user_id = query.from_user.id
await query.answer()

try:
member = await context.bot.get_chat_member(chat_id=f"@{CHANNEL_USERNAME}", user_id=user_id)
if member.status in ['member', 'administrator', 'creator']:
await query.edit_message_text("✅ Verification successful! You now have access.")
# Additional features can be added here
else:
await query.edit_message_text("❌ You are not a member of the channel.")
except:
await query.edit_message_text("⚠️ Unable to verify. Please try again later.")

if __name__ == '__main__':
app = ApplicationBuilder().token(BOT_TOKEN).build()
app.add_handler(CommandHandler("start", start))
app.add_handler(CallbackQueryHandler(button_handler))
print("Bot is running...")
app.run_polling()

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.