Спасибо.
Код: Выделить всё
import telegram
from telegram import Update
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler
# Replace with your bot token
BOT_TOKEN = 'YOUR_BOT_TOKEN'
async def get_high_scores(update: Update, context: ContextTypes.DEFAULT_TYPE):
"""Retrieves and displays game high scores."""
try:
# Replace with the user_id or chat_id of the user you want to get scores for
user_id = update.effective_user.id
chat_id = update.effective_chat.id
# Get high scores
high_scores = await context.bot.get_game_high_scores(user_id=user_id, chat_id=chat_id)
# Format the high scores as HTML
html_text = "High Scores:[/b][b]"
if high_scores:
for score in high_scores:
html_text += f"{score.user.username}:[/b] {score.score}
"
else:
html_text += "No high scores yet.
"
# Send the HTML formatted message
await context.bot.send_message(chat_id=chat_id, text=html_text, parse_mode=telegram.constants.ParseMode.HTML)
except Exception as e:
print(f"Error getting high scores: {e}")
await context.bot.send_message(chat_id=chat_id, text="Error getting high scores.")
# Create the Telegram Application
if __name__ == '__main__':
application = ApplicationBuilder().token(BOT_TOKEN).build()
# Add a command handler for the high scores command
high_scores_handler = CommandHandler("highscores", get_high_scores)
application.add_handler(high_scores_handler)
# Start the bot
application.run_polling()
Подробнее здесь: https://stackoverflow.com/questions/795 ... lay-result
Мобильная версия