smitmartijn / discord-table-builder
一个简单的包,用于在 Discord 消息中创建表格。
v1.0.0
2024-09-11 17:34 UTC
Requires
- php: >=7.2
README
这个 PHP 包是一个简单的辅助工具,用于创建 Discord 消息的表格,因为没有内置的创建表格的方式。发送包含该包结果的嵌套消息来格式化 Discord 消息中的出色表格。
- 根据内容确定每列的宽度
- 行/列无限(取决于 Discord API)
- 将行链接到 URL
安装
composer require smitmartijn/discord-table-builder
用法
<?php require_once __DIR__ . '/vendor/autoload.php'; use Smitmartijn\DiscordTableBuilder; // Example: Game Leaderboard Table $table = new DiscordTableBuilder\DiscordEmbedTable([ 'titles' => ['Position', 'Player', 'Points'], 'padding' => 8 ]); $table->addRow(['1st', 'Charlie', '300'], ['url' => 'https://lostdomain.org']); $table->addRow(['2nd', 'Alice', '100']); // From here you can use the $table object to render the table in a Discord API call $messageContent = [ "tts" => false, "embeds" => [ [ "title" => "Weekly Leaderboard", "description" => "Here are the top users for the last week!", "fields" => [$table->toField()], ] ] ]; // use your own function to send the message to Discord sendToDiscord($messageContent);
示例输出
这里是一个 DiscordTableBuilder 的示例,展示了在单个嵌套消息中使用多个表格。
toField()
方法返回一个 Discord 嵌套字段对象。您可以在 Discord API 调用中使用此对象来在 Discord 消息中渲染表格。
/**
* The toField() method returns the following structure, nicely formatted as a table:
*
* [`1st Charlie 300`](https://whatpulse.org)
* [`2nd Dana 250`](https://typetest.io)
* [`3rd Eve 200`](https://lostdomain.org)
* [`4th Bob 150`](https://mutedeck.com)
* `5th Alice 100`"
*/
贡献
欢迎提交拉取请求。对于主要更改,请先打开一个问题来讨论您想要进行的更改。
许可
此包根据 GNU 通用公共许可证 v3.0 授权。有关更多信息,请参阅LICENSE文件。