florianrambur/discord-webhook
最新稳定版本:1.2.1
Composer 安装命令:
composer require florianrambur/discord-webhook
包简介
README 文档
README
Installation
composer require florianrambur/discord-webhook
Usage
Here is a simple example
<?php use FlorianRambur\DiscordWebhook\Client; $config = [ 'url' => 'https://your-discord-webhook-url', 'author' => [ 'username' => 'Florian', 'avatar_url' => 'https://i.imgur.com/ZGPxFN2.jpg', ], ]; $client = new Client($config); $response = $client->send([ 'content' => 'This is the main content', ]);
Work with Embed
This package give you the opportunity to work with a simple Embed class that allow you to create an advanced message. To do that, you can pass data into the constructor or use some methods like name($value)
<?php $embed = (new Embed()) ->add(new Author([ 'name' => 'This is the author', 'url' => 'https://github.com/florianrambur/discord-webhook', 'icon_url' => 'https://github.com/florianrambur/discord-webhook/icon.jpg', ])) ->add(new Body([ 'title' => 'Webhook Title', 'description' => 'Webhook Description', 'color' => 5814783, ])) ->add(new Image([ 'images' => ['https://i.imgur.com/ZGPxFN2.jpg'], ])) ->add(new Footer([ 'text' => 'This is the footer', 'timestamp' => '2021-07-06T22:00:00.000Z', ]));
<?php $author = (new Author()) ->name('This is the author') ->url('https://github.com/florianrambur/discord-webhook') ->iconUrl('https://github.com/florianrambur/discord-webhook/icon.jpg'); $body = (new Body()) ->title('Webhook Title') ->description('Webhook Description') ->color(5814783); $image = (new Image())->image('https://i.imgur.com/ZGPxFN2.jpg'); $footer = (new Footer()) ->text('This is the footer') ->timestamp('2021-07-06T22:00:00.000Z'); $embed = (new Embed())->addMany([$author, $body, $image, $footer]);
The Embed provides two methods to add an attribute class
<?php (new Embed()) ->add($body) ->add($footer); (new Embed())->addMany([$body, $footer]);
Then, pass your data and your config to the Client class
<?php $config = [ 'url' => 'https://your-discord-webhook-url', 'author' => [ 'username' => 'Florian', 'avatar_url' => 'https://i.imgur.com/ZGPxFN2.jpg', ], ]; $client = new Client($config); $response = $client->send([ 'embeds' => [ $embed->toArray(), ], ]);
What's next
This package is under development and few things are missing :
- some constraints on attributes are missing
- few templates will be created to give you the possibility to create a message easier and faster
统计信息
- 总下载量: 957
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-10