-
-
Notifications
You must be signed in to change notification settings - Fork 249
Discord
Discord is the main object of your Discord BOT Application
Creates a Discord client instance.
public __construct([array<string|int, mixed> $options = [] ]) : mixedExample
$discord = new Discord([
'token' => 'bot-token',
]);Return
- Discord the bot instance
Closes the Discord client.
public close([bool $closeLoop = true ]) : voidExample
$discord->close();Allows access to the part/repository factory.
public factory(string $class[, mixed $data = [] ][, bool $created = false ]) : Part|AbstractRepositoryThe use of factory with part is possible with the new Part($discord, $data, $created);
Example
// Preferred way
$channel = new Channel($discord, ['name' = 'newchannel']);
// Is equivalent to:
$channel = $discord->factory(Channel::class, ['name' => 'newchannel']);Return
- Part the bot Part Factory
- Repository the bot Repository Factory
Gets a channel.
public getChannel(string|int $channel_id) : Channel|nullExample
$channel = $discord->getChannel('012345678910111213');Return
- Channel the channel or private channel part
Gets the factory.
public getFactory() : FactoryExample
$factory = $discord->getFactory();Return
- Factory the bot Factory object
Gets the HTTP client.
public getHttpClient() : HttpExample
$httpClient = $discord->getHttpClient();Return
- Http the bot Http object
Gets the logger being used.
public getLogger() : LoggerInterfaceExample
$logger = $discord->getLogger();Return
- LoggerInterface the Logger interface
Gets the loop being used by the bot client.
public getLoop() : LoopInterfaceExample
$loop = $discord->getLoop();Return
- LoopInterface the bot Loop interface
Gets the bot voice client from a guild ID. Returns null if there is no voice client.
public getVoiceClient(string $guild_id) : VoiceClient|nullExample
$voiceClient = $discord->getVoiceClient('012345678910111213');Return
- VoiceClient the bot Voice Client
-
nullthe bot has no Voice Client
Joins a voice channel.
public joinVoiceChannel(Channel $channel[, bool $mute = false ][, bool $deaf = true ][, LoggerInterface|null $logger = null ][, bool $check = true ]) : PromiseInterfaceExample
$discord->joinVoiceChannel($channel)->then(function (VoiceClient $vc) {
echo "Joined voice channel.\r\n";
$vc->playFile('myfile.mp3');
}, function ($e) {
echo "There was an error joining the voice channel: {$e->getMessage()}\r\n";
});Return
- PromiseInterface the promise when bot has joined the voice channel
Starts the ReactPHP event loop.
public run() : voidExample
// Should be placed at bottom of the script
$discord->run();Updates the clients presence.
public updatePresence([Activity|null $activity = null ][, bool $idle = false ][, string $status = 'online' ][, bool $afk = false ]) : voidSee Activity
API Documentation: https://discord.com/developers/docs/topics/gateway#update-presence
Example
$activity = new Activity($discord, [
'name' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
'type' => Activity::TYPE_WATCHING
]);
$discord->updatePresence($activity);To handle various events from Discord, you can use $discord->on(EVENTNAME, CALLBACK);
This event is called when the Discord BOT is ready (connected online).
public const READY = 'READY' Gateway events should be registered inside the ready event, which is emitted once when the bot first starts and has connected to the gateway.
Example
$discord->on('ready', function ($discord) {
echo "Bot is ready.", PHP_EOL;
});Note: This wiki is currently Work In Progress. Consider reading the docs instead.
- Application Command (Slash based)
Command Client (Message based)
- Activity
- Application
- Guild
- Private Channel
- User
Components
-
ActionRow
- Buttons
- Option (commands)
- SelectMenu
- TextInput
Builders