- A simple and efficient Telegram bot for playing chess, built using Aiogram.
- This bot operates in inline mode, allowing users to play chess with other chat participants.
- All moves are reflected and updated in the original message, ensuring a seamless gaming experience.
This project utilizes the python-chess library by niklasf for chess logic and operations.
Want to give it a shot before installing? It's easy! Simply type @nujno_mnogo_rabot
in any chat on Telegram and click "Play Chess".
pip install telegram-chess
- Download the
telegram_chess.py
file. - Place it in your project directory.
from aiogram import Bot, Dispatcher, Router, types, F
from aiogram.enums import ParseMode
from aiogram.types import Message, InlineQuery
import asyncio
from telegram_chess import TelegramChess
TOKEN = "BOT_TOKEN_GOES_HERE"
bot = Bot(token=TOKEN, parse_mode=ParseMode.HTML)
dp = Dispatcher()
chess_game = TelegramChess()
@dp.inline_query()
async def inline_echo(inline_query: types.InlineQuery):
await chess_game.answer_with_inline_chess_query(inline_query)
@dp.callback_query(F.data.startswith(chess_game.chess_data_start))
async def handle_callback(callback_query: types.CallbackQuery):
await chess_game.make_move(callback_query, bot)
async def on_startup():
print("Welcome to Chess Bot by @EnMind")
async def main() -> None:
await dp.start_polling(bot)
await on_startup()
if __name__ == "__main__":
asyncio.run(main())
Enjoy playing chess with your friends on Telegram!