discord php
1.0.0
discord php是一个 PHP 库,旨在包含并简化网站、在线应用程序和 Discord 之间的创建和连接。
只需要 PHP 5.6+。让我们开始下载 Discord-php 库,然后将其解压到your_server_path/
。
一种快速方法是导入Autoload.php
:
require_once ( " /your/custom/path/to/discord-php/Autoload.php " );
此外,您可以只包含您需要的课程:
// Required
require_once ( " ./Discord.php " );
require_once ( " ./Client.php " );
// Optional
include_once ( " ./Discord/Guilds.php " );
include_once ( " ./Discord/Channels.php " );
在使用discord php lib之前,您必须创建您的 Discord 应用程序,然后创建一个“新配置对象”。如下:
$ configs = array ();
$ configs [ " token " ] = " YOUR_BOT_TOKEN " ;
$ configs [ " authType " ] = " Bot " ; // Optional (Default: "Bot")
$ configs [ " client_id " ] = " YOUR_CLIENT_ID " ; // Optional (Default: null)
$ configs [ " client_secret " ] = " YOUR_CLIENT_SECRET " ; // Optional (Default: null)
$ configs [ " public_key " ] = " YOUR_PUBLIC_KEY " ; // Optional (Default: null)
$ configs [ " stash " ] = array ( // Optional
" Guild Name " => array (
" guild_id " => " YOUR_SERVER_ID " ,
" channels " => array (
" Channel Name " => " YOUR_CHANNEL_ID "
),
" roles " => array (
" Role Name " => " YOUR_ROLE_ID "
),
" members " => array (
" Member Name " => " YOUR_MEMBER_USER_ID "
)
)
);
$ discord_configs = New Discord Configs ( $ configs );
在哪里:
client_id
= @me
- oAuth2 /令牌交换请求所需;;client_secret
= oAuth2 /令牌交换请求所需;token
= 任何API 请求(例如New DiscordClientUsers("USER_ID");
;您还可以使用文件./Configs.php
轻松添加所有 Discord 应用程序信息,然后包括以下内容:
$ discord_configs = New Discord Configs ( include ( " ./Configs.php " ));
根据您的 Discord 配置创建一个 Discord 客户端,以发送 Discord API 请求,如下所示:
$discord = New DiscordClient($discord_configs);
您现在可以按照您的意愿使用discord php库了!您需要了解的有关该库的所有信息,例如类和“如何使用”,都在 Wiki 中进行了描述。我希望这个库能帮助您在 PHP 中进行 Discord 编码。任何建议或改进总是受欢迎的。
require_once ( " ./Autoload.php " );
$ configs = include ( " ./Configs.php " );
$ discord = New Discord Client ( New Discord Configs ( $ configs ));
// Guilds
$ guild = New Discord Client Guilds ( $ discord , " GUILD_ID " );
$ members = $ guild -> members ();
$ specific_member = $ guild -> members ( " USER_ID " ); // Will return a DiscordClientMembers Object
$ channels = $ guild -> channels ();
$ specific_channel = $ guild -> channels ( " CHANNEL_ID " ); // Will return a DiscordClientChannels Object
// Channels
$ channel = New Discord Client Channels ( $ discord , " CHANNEL_ID " );
$ messages = $ channel -> messages ();
$ specific_message = $ channel -> message ( " MESSAGE_ID " ); // Will return a DiscordClientMessages Object
$discord->stash
在开始之前,您必须了解有关“Stash”对象的更多信息:首先,stash 是在创建新的 Discord 配置期间要设置的可选数组。遵循示例中提出的标准,您可以轻松使用“Discord Client”进行API响应,如下所示:
$ configs = array (
" token " => " YOUR_BOT_TOKEN " ,
" stash " => array (
" CUSTOM_GUILD_NAME " => array (
" guild_id " => " YOUR_GUILD_ID "
"channels" => array (
" CUSTOM_CHANNEL_NAME " => " YOUR_CHANNEL_ID "
)
),
" CUSTOM_GUILD_NAME_2 " => array (
" channels " => array (
" CUSTOM_CHANNEL_NAME_2 " => " YOUR_CHANNEL_ID_2 "
)
)
)
);
$ discord = New Discord Client ( New Discord Configs ( $ configs ));
// Get a DiscordClientGuilds directly from the client using your Stash
// Please, make sure you've correctly imported ./Discord/Guilds.php class before.
// Also, make sure you're using the right $config standard and "GUILD_NAME" in order to get automatically a GUILD_ID
$ guild = $ discord -> Guilds ( " CUSTOM_GUILD_NAME " );
// You can also send a custom Guild ID
$ guild = $ discord -> Guilds ( " GUILD_ID " );
// You can do the same for the channels
// Make sure you've correctly imported ./Discord/Channels.php class before
$ channel = $ discord -> Channels ( " CUSTOM_CHANNEL_NAME_2 " );
// And then, to get a channel using a custom Channel ID
$ channel = $ discord -> Channels ( " CHANNEL_ID " );