Spaces:
Runtime error
Runtime error
Delete Bot
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394$ pip install python-telegram-bot --upgrade
import loggingimport randomfrom telegram import Update, InlineKeyboardButton, InlineKeyboardMarkupfrom telegram.ext import ApplicationBuilder, CommandHandler, MessageHandler, filters, CallbackQueryHandler
# Enable logginglogging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)logger = logging.getLogger(__name__)
# Fun fact listfun_facts = [ "Did you know? Honey never spoils.", "Fact: Bananas are berries, but strawberries aren't.", "Fun Fact: Octopuses have three hearts!", "Legendary: The Eiffel Tower can grow by 6 inches in summer due to heat expansion.", "Myth or fact? You can't hum while holding your nose closed."]
# Start commandasync def start(update: Update, context) -> None: await update.message.reply_text( f"Welcome to the legendary Error404Bot!\nI'm here to assist you with the best features.\nUse /help to see more commands." )
# Help commandasync def help_command(update: Update, context) -> None: await update.message.reply_text( "/start - Start interacting with the bot.\n" "/welcome - Sends a custom welcome message.\n" "/fact - Get a fun fact." )
# Welcome message functionasync def welcome(update: Update, context) -> None: user = update.effective_user welcome_text = f"Welcome, {user.first_name}, to the legendary Error404Bot community! Prepare to be amazed. 😎" keyboard = [ [InlineKeyboardButton("Learn More", callback_data='learn_more')], [InlineKeyboardButton("Support", callback_data='support')] ] reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(welcome_text, reply_markup=reply_markup)
# Fun fact featureasync def send_fun_fact(update: Update, context) -> None: fact = random.choice(fun_facts) await update.message.reply_text(fact)
# Button handler (for Learn More and Support)async def button(update: Update, context) -> None: query = update.callback_query await query.answer()
if query.data == 'learn_more': await query.edit_message_text(text="This bot is designed to provide legendary services and features.") elif query.data == 'support': await query.edit_message_text(text="Support is on the way! Please wait for a response or contact @support.")
# Error handlerasync def error_handler(update: object, context) -> None: logger.error(msg="Exception while handling an update:", exc_info=context.error)
# Main function to run the botasync def main() -> None: # Create the Application and pass it your bot's token. application = ApplicationBuilder().token("7813873560:AAFW6_I_n9OYgbycJZsL92ns1SuXsrYLTI0").build()
# Register command handlers application.add_handler(CommandHandler("start", start)) application.add_handler(CommandHandler("help", help_command)) application.add_handler(CommandHandler("welcome", welcome)) application.add_handler(CommandHandler("fact", send_fun_fact)) # Button handler for interactive buttons application.add_handler(CallbackQueryHandler(button))
# Log all errors application.add_error_handler(error_handler)
# Start the bot await application.start_polling() await application.idle()
# Run the botif __name__ == '__main__': import asyncio asyncio.run(main())BotDeleted-94