tassilo / discord-webhooks
此包已被弃用,不再维护。未建议任何替代包。
一个简单的PHP库,用于执行Discord钩子。
dev-master
2020-06-28 19:09 UTC
Requires
- ext-curl: *
- ext-json: *
This package is auto-updated.
Last update: 2021-10-28 21:59:36 UTC
README
一个简单、单文件的PHP库,用于执行Discord钩子。
示例
首先,您需要包含DiscordWebhooks.php
文件。将路径更改为您存储的位置。
include(__DIR__ . '/DiscordWebhooks.php'); const URL = 'https://discordapp.com/api/webhooks/{webhook.id}/{webhook.token}';
您可以使用链式语法快速执行钩子
// Chain Syntax (new DiscordWebhook())->setContent('A chained webhook!')->execute(URL);
您还可以执行更复杂的钩子,如下所示
$webhook = new DiscordWebhook(); $webhook->setContent('Hello World!'); $webhook->setUsername('Octocat'); $webhook->setAvatarURL('https://github.githubassets.com/images/modules/logos_page/Octocat.png'); $embed = new DiscordWebhookEmbed(); $embed->setTitle('This is the title!'); $embed->setDescription('And this is the description! It supports **Markdown**!'); $embed->setURL('https://github.com/'); $embed->setTimestamp(time()); $embed->setColor(255, 0, 0); $embed->setFooter('Posted by the cool Octocat!', 'https://github.githubassets.com/images/modules/logos_page/Octocat.png'); $embed->setThumbnail('https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png'); $embed->setImage('https://github.githubassets.com/images/modules/logos_page/GitHub-Logo.png'); $embed->setAuthor('Pikachuuuu', 'https://github.com/TASSIA710', 'https://avatars1.githubusercontent.com/u/38081490'); $embed->addField(new DiscordWebhookEmbedField('Cool field!', 'This is a very cool field. **Markdown** is supported here aswell.')); $embed->addField(new DiscordWebhookEmbedField('2nd cool field!', 'These two fields', true)); $embed->addField(new DiscordWebhookEmbedField('3rd cool field!', 'are inline!', true)); $webhook->addEmbed($embed); echo $webhook->execute(URL);
要求
此库需要安装以下扩展
curl
json