A modern Discord bot framework for PHP built on top of Tempest. Tempcord provides a clean, expressive API for building Discord bots with PHP 8.2+.
- 🚀 Modern PHP: Built for PHP 8.2+ with full type safety
- ⚡ Tempest Integration: Leverages the powerful Tempest framework
- 🎯 Discord API: Full Discord API v10 support
- 🔧 Developer Friendly: Intuitive API with excellent IDE support
- 📦 Composer Ready: Easy installation and dependency management
- 🧪 Testing: Built-in testing support with PHPUnit and Pest
- 📚 Well Documented: Comprehensive documentation and examples
You can create a new Tempcord project using Composer:
composer create-project tempcord/tempcord my-discord-bot
cd my-discord-botOr install it in an existing project:
composer require tempcord/tempcordCopy the example environment file and configure your Discord bot token:
cp .env.example .envEdit .env and add your Discord bot token:
DISCORD_TOKEN=your_bot_token_hereCreate a simple ping command in app/Commands/PingCommand.php:
<?php
namespace App\Commands;
use Tempcord\Attributes\Command;
use Tempcord\Attributes\Description;
use Tempcord\Discord\Interaction;
#[Command('ping')]
class PingCommand
{
public function handle(Interaction $interaction): void
{
$interaction->reply('🏓 Pong!');
}
}php tempcord boot<?php
namespace App\Commands;
use Tempcord\Attributes\Command;
use Tempcord\Attributes\Description;
use Tempcord\Attributes\Option;
use Tempcord\Discord\Interaction;
use Tempcord\Enums\OptionType;
class GreetCommand
{
#[Command('greet')]
#[Description('Greet a user')]
#[Option('user', OptionType::USER, 'The user to greet', required: true)]
#[Option('message', OptionType::STRING, 'Custom greeting message')]
public function handle(Interaction $interaction): void
{
$user = $interaction->getOption('user');
$message = $interaction->getOption('message') ?? 'Hello';
$interaction->reply("{$message}, {$user->mention()}!");
}
}<?php
namespace App\Listeners;
use Tempcord\Attributes\EventListener;
use Tempcord\Events\MessageCreate;
class MessageListener
{
#[EventListener]
public function onMessageCreate(MessageCreate $event): void
{
$message = $event->message;
if ($message->content === '!hello') {
$message->reply('Hello there!');
}
}
}<?php
namespace App\Middleware;
use Tempcord\Attributes\Middleware;
use Tempcord\Discord\Interaction;
use Tempcord\Middleware\MiddlewareInterface;
#[Middleware]
class AdminOnlyMiddleware implements MiddlewareInterface
{
public function handle(Interaction $interaction, callable $next): mixed
{
if (!$interaction->member->hasPermission('ADMINISTRATOR')) {
$interaction->reply('❌ This command requires administrator permissions.');
return;
}
return $next($interaction);
}
}Tempcord uses a simple configuration system. You can customize your bot's behavior in app/config/tempcord.config.php:
<?php
use Tempcord\Config\TempcordConfig;
return new TempcordConfig(
token: env('DISCORD_TOKEN'),
clientId: env('DISCORD_CLIENT_ID'),
intents: [
'GUILDS',
'GUILD_MESSAGES',
'MESSAGE_CONTENT',
],
commandPrefix: '!',
autoRegisterCommands: true,
);Run the test suite:
composer testRun tests with coverage:
composer test-coverageRun static analysis:
composer analyseFormat code:
composer formatIf you discover a security vulnerability within Tempcord, please send an e-mail to the maintainers via mikield@icloud.com. All security vulnerabilities will be promptly addressed.
Tempcord is open-sourced software licensed under the MIT license.