Laracord comes with various hooks and override-able methods to initialize your own classes alongside the boot process. This is primarily done in app/Bot.php
.
The beforeBoot()
method can be defined to run code before the bot is booted. This is useful for initial configuration or other pre-boot tasks.
/**
* Actions to run before booting the bot.
*/
public function beforeBoot(): void
{
ini_set('memory_limit', '-1');
cache()->flush();
}
The afterBoot()
method can be defined to run code after the bot is booted. This typically happens the first time the Discord ready
event is fired.
Here's an example setting the bot's activity presence on boot:
use Discord\Parts\User\Activity;
/**
* Actions to run after booting the bot.
*/
public function afterBoot(): void
{
$activity = $this->discord()->factory(Activity::class, [
'type' => Activity::TYPE_PLAYING,
'name' => 'with Laracord',
]);
$this->discord()->updatePresence($activity);
}