ryantxr / discord-webhook
向Discord发送消息。
1.0.6
2023-02-10 05:38 UTC
Requires
- php: >=7.1.8 || ^8.0
- guzzlehttp/guzzle: ^7.4.5 || ^6.3.0
- nesbot/carbon: ^2.20
- psr/log: ^1.1.0
Requires (Dev)
README
此库提供了一个Discord Webhooks的客户端。通过最少的代码,您应该能够向Discord频道发送消息。
如果您需要做更多,比如嵌入和格式化,您也可以这样做。
动机
我看了其他库,它们已经存在很长时间了。感谢它们支持嵌入和一些有趣的功能。然而,我没有看到一种只用一行代码发送消息的方法。我只想向频道发送一条文本消息。
此库与服务容器兼容。
入门
您可以直接将PHP文件复制到您的项目中,或者更理想的是使用Composer。
Composer require命令
composer require ryantxr/discord-webhook
功能
- 发送消息的极简代码
- 与服务容器兼容
- 使用PHPUnit进行单元测试
- 易于在任何框架或纯PHP文件中使用
使用方法
<?php use Ryantxr\Discord\Webhook\Client as Webhook; $webhook = new Webhook( 'YOUR_DISCORD_WEBHOOK_URL' ); $webhook->message('This is a message');
嵌入
Discord有使用嵌入创建更有趣帖子的方法。
use Ryantxr\Discord\Webhook\Client as Webhook; use Ryantxr\Discord\Webhook\Embed; // Get this from some config $webhookConfig = [ 'url' => 'YOUR_DISCORD_WEBHOOK_URL', 'username' => 'funnybot', 'avatar' => 'https://pbs.twimg.com/media/C51iiP9UYAIPpWP.png', ]; $webhook = new Webhook( $webhookConfig ); $embed = new Embed('SOME_URL_YOU_WANT'); $embed->title('This is a title') ->author('Justin', 'https://authors-website.com', 'https://discordapp.com/assets/28174a34e77bb5e5310ced9f95cb480b.png') ->field('Field 1', 'Some cool text', true ) ->field('Field 2', 'Another cool text', true ) ->color(15158332) ; $webhook->send($embed, "A message goes here.");
以下是一个官方颜色列表,用于着色您的嵌入
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