snowrunescape/discord-bot-php
最新稳定版本:v3.2.0
Composer 安装命令:
composer require snowrunescape/discord-bot-php
包简介
Discord Bot PHP
README 文档
README
DiscordBot-PHP is a powerful PHP module that allows you to easily interact with the Discord API.
Installation
Preferred way to install is with Composer.
composer require snowrunescape/discord-bot-php
PHP 7.4 or newer is required.
Example usage
You can see an example of how to use it by clicking here.
require_once "vendor/autoload.php"; use DiscordPHP\Discord; $discord = new Discord("YOU_DISCORD_BOT_TOKEN"); $discord->run();
Register commands and events before triggering the $discord->run();
To register a command use the code
$discord->event->registerCommand(new Ping($discord));
To register events use the code
$discord->event->registerEventHandler(new MESSAGE_CREATE($discord));
Example Command
class Ping extends DiscordCommand { public function getCommand() { return "!ping"; } public function onInit() { Logger::Info("Starting command..."); } public function run(array $event, array $args) { $this->discord->discordAPI->createMessage("Pong!", $event["channel_id"]); } }
Events can be created inside commands, to keep the code organized
public function MESSAGE_CREATE($event) { Logger::Info("This event handler has been called!"); }
Example eventHandler
class MESSAGE_CREATE extends DiscordEventHandler { public function onInit() { Logger::Info("Starting eventHandler..."); } public function run(array $event) { Logger::Info("This event handler has been called!"); } }
Credits
Help
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official DiscordBot-PHP Server.
统计信息
- 总下载量: 56
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2022-12-18