labymod / discord-webhooks
1.1.1
2017-11-02 22:45 UTC
Requires
- php: >=5.4
- ext-curl: *
README
Discord webhooks 是 Discord webhook API 的简单客户端。
动机
虽然这可能是 Discord webhook 系统的“另一个”库,但我还是想自己做一个。Discord 不支持 BitBucket 的 webhook 系统,且与 Slack 兼容的端点不发送消息。
入门
您可以直接将 PHP 文件复制到您的项目中,或者更推荐使用 composer。
Composer require 命令
composer require nopjmp/discord-webhooks
用法
使用起来相当简单。我将提供一个示例。
<?php use \Discord\Webhook; use \Discord\Embed; $webhook = new Webhook( 'DISCORD_WEBHOOK_URL' ); $embed = new Embed(); $embed->setDescription( 'This is an embed' ); $webhook->setUsername( 'Bot' )->setMessage( 'Hello, Human!' )->setEmbed( $embed )->send();
这里还有一个示例。让我们发送一些文件。
$webhook = new Webhook( 'DISCORD_WEBHOOK_URL' ); $file = new File( "filename.jpg", "postname.jpg"/*optional*/ ); $webhook ->setUsername( 'Bot' ) /*optional*/ ->setAvatar( 'https://example.com/bot.jpg' ) /*optional*/ ->setMessage( 'Hello, Human!' ) /*optional*/ ->setFile( $file ) ->send();
为了正确地样式化您的嵌入,您可以查看这个网站: https://cog-creators.github.io/discord-embed-sandbox/
也许这个网站可以帮助您正确地构建嵌入;)
高级示例
Aaaaaand 这里是代码
<?php use Discord\Webhook; $wh = new Webhook( 'YOUR_WEBHOOK_URL' ); $embed = new \Discord\Embed(); $thumbnail = new \Discord\Embed\EmbedThumbnail(); $author = new \Discord\Embed\EmbedAuthor(); $field1 = new \Discord\Embed\EmbedField(); $field2 = new \Discord\Embed\EmbedField(); $field3 = new \Discord\Embed\EmbedField(); $footer = new \Discord\Embed\EmbedFooter(); $thumbnail->setUrl( 'https://pbs.twimg.com/media/C--1DR0UIAEr6Bw.png' ); $author ->setName( 'Discord' ) ->setIconUrl( 'https://discordapp.com/assets/28174a34e77bb5e5310ced9f95cb480b.png' ) ->setUrl( 'https://discordapp.com/' ); $field1 ->setName( 'Field 1' ) ->setValue( 'Some cool text' ) ->setInline( true ); $field2 ->setName( 'Field 2' ) ->setValue( 'Another cool text' ) ->setInline( true ); $field3 ->setName( 'Field 3' ) ->setValue( 'A full width field where I can write some more text' ); $footer->setText( 'Here goes the footer' ); $embed ->setTitle( 'This is my title' ) ->setDescription( 'Another fancy description' ) ->setColor( 15158332 ) ->setThumbnail( $thumbnail ) ->setAuthor( $author ) ->setField( $field1 ) ->setField( $field2 ) ->setField( $field3 ) ->setFooter( $footer ); $wh ->setUsername( 'Fancy Bot' ) ->setAvatar( 'https://pbs.twimg.com/media/C51iiP9UYAIPpWP.png' ) ->setEmbed( $embed ) ->send();
这是官方颜色列表,可用于着色您的嵌入
DEFAULT: 0, AQUA: 1752220, GREEN: 3066993, BLUE: 3447003, PURPLE: 10181046, GOLD: 15844367, ORANGE: 15105570, RED: 15158332, GREY: 9807270, DARKER_GREY: 8359053, NAVY: 3426654, DARK_AQUA: 1146986, DARK_GREEN: 2067276, DARK_BLUE: 2123412, DARK_PURPLE: 7419530, DARK_GOLD: 12745742, DARK_ORANGE: 11027200, DARK_RED: 10038562, DARK_GREY: 9936031, LIGHT_GREY: 12370112, DARK_NAVY: 2899536
许可证
该项目采用 MIT 许可。要查看完整许可证,请打开 LICENSE.md。
贡献
拉取请求和问题都是开放的!