A Magic: The Gathering API Library and bot for Discord, built using DiscordPHP.
- Search cards by any MTG API filter (name, colors, type, set, format legality, …) and fetch a card by id
- Look sets up by name or block, and open a booster pack for a set
- Read the API reference lists: card types, subtypes, supertypes and game formats
- Rich card rendering for Discord: Components V2 container, mana/symbol emojis, plus buttons for the raw JSON, image, rulings, legalities, foreign names and set
- Ships as an installable slash-command bot (
/card_search), user-installable and usable anywhere
- PHP 8.3 or higher
- Composer
-
Clone the repository:
git clone https://github.com/discord-php/DiscordPHP-MTG.git cd DiscordPHP-MTG -
Install dependencies:
composer install
- Copy and rename
.env.exampleto.envand configure your bot token. - Run the bot:
php bot.php
- Alternatively, package the bot into an executable binary:
composer run-script phpacker
MTG extends the DiscordPHP client, so the MTG repositories hang off it and every call returns a promise:
$mtg = new \MTG\MTG(['token' => getenv('TOKEN')]);
$mtg->cards->getCards(['name' => 'Black Lotus'])->then(fn ($cards) => $cards->first());
$mtg->cards->fetch('cardId')->then(fn ($card) => $card);
$mtg->sets->getSets(['name' => 'Khans of Tarkir'])->then(fn ($sets) => $sets->first());
$mtg->sets->generateBooster('KTK')->then(fn ($pack) => $pack); // needs a self-hosted mtg-api
$mtg->getTypes(); // ['Artifact', 'Creature', 'Instant', …]
$mtg->getSubtypes(); // ['Elf', 'Equipment', …]
$mtg->getSupertypes(); // ['Basic', 'Legendary', 'Snow', …]
$mtg->getFormats(); // ['Standard', 'Modern', 'Commander', …]Pass mtg_api_key in the options array to send an X-Api-Key header for a higher rate limit.
See CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License. See LICENSE.md for details.