Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/commandstring/phpcord
A modern discord api wrapper in PHP
https://github.com/commandstring/phpcord
composer discord discord-api discord-api-wrapper php php8 php81 php82
Last synced: 26 days ago
JSON representation
A modern discord api wrapper in PHP
- Host: GitHub
- URL: https://github.com/commandstring/phpcord
- Owner: CommandString
- License: mit
- Created: 2023-09-06T01:09:37.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-26T21:19:52.000Z (12 months ago)
- Last Synced: 2024-10-12T12:42:09.517Z (26 days ago)
- Topics: composer, discord, discord-api, discord-api-wrapper, php, php8, php81, php82
- Language: PHP
- Homepage:
- Size: 172 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PHPCord
A modern Discord API wrapper for PHP
**NOTE**: This is still in development and is not ready for production use
## Requirements
- PHP 8.1+
- Composer## Resources
- [Discord Developer Portal](https://discord.com/developers/docs/intro)
## Installation
```bash
composer require phpcord/phpcord
```## Example
```php
withRest(
new Guzzle(options: ['verify' => false])
)->withGateway();define('START_TIME', time());
$bot->gateway->onEvent(Event::READY, static function (Ready $ready) use ($bot) {
LOGGER->info("{$ready->user->username} is ready!");return; // remove to register command
$command = new ApplicationCommand();
$command->name = 'status';
$command->description = 'Get the status of the bot';$typeOption = new ApplicationCommandOption();
$typeOption->name = 'type';
$typeOption->description = 'The type of status';
$typeOption->type = ApplicationCommandOptionType::STRING;
$typeOption->required = true;$typeOptionRam = new ApplicationCommandOptionChoice();
$typeOptionRam->name = $typeOptionRam->value = 'ram';$typeOptionUptime = new ApplicationCommandOptionChoice();
$typeOptionUptime->name = $typeOptionUptime->value = 'uptime';$typeOption->choices = [$typeOptionRam, $typeOptionUptime];
$command->options = [$typeOption];await($bot->rest->guildCommands->createCommand($ready->application->id, '988910112825548811', $command));
LOGGER->info('Created status command!');
});$bot->gateway->onEvent(Event::INTERACTION_CREATE, static function (Interaction $interaction) use ($bot) {
if (
$interaction->type !== InteractionType::APPLICATION_COMMAND ||
$interaction->data->name !== 'status'
) {
return;
}$type = $interaction->data->options[0]->value;
if ($type === 'ram') {
$messageContent = 'RAM Usage is ' . round(memory_get_usage() / 1024 / 1024, 2) . 'MB';
} else if ($type === 'uptime') {
$messageContent = 'The bot was started ';
}$response = new InteractionResponse();
$response->type = InteractionResponseType::CHANNEL_MESSAGE_WITH_SOURCE;
$response->data = (new MessageBuilder())
->withContent($messageContent)
->withFlags(MessageFlag::EPHEMERAL)
->build();$bot->rest->interactions->createResponse(
$interaction->id,
$interaction->token,
$response
);
});$bot->gateway->start();
```