discord-php-extended / discordphp-mtg
API Library for api.magicthegathering.io built on top of DiscordPHP.
v0.10.2
2026-09-07 09:52 UTC
Requires
- discord-php/http: dev-master as 10.1.7
- team-reflex/discord-php: * || dev-master
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- laravel/pint: ^1.21
- phpacker/phpacker: ^0.6.4
- phpunit/phpunit: ^9.4.4
- wyrihaximus/react-cache-redis: ^4.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-09 15:28:37 UTC
README
A Magic: The Gathering API Library and bot for Discord, built using DiscordPHP.
Features
- 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
Requirements
- PHP 8.3 or higher
- Composer
Installation
-
Clone the repository:
git clone https://github.com/discord-php/DiscordPHP-MTG.git cd DiscordPHP-MTG -
Install dependencies:
composer install
Usage
- 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
As a library
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.
Contributing
See CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License. See LICENSE.md for details.