Events
Events in ShadowCore allow you to hook into various lifecycle stages of the bot and respond to them. They are an essential part of the botโs behavior, as they allow you to execute code when specific actions or triggers occur, such as when the bot logs in, a user sends a message, or a button is clicked.๐ Event Structure
Events in ShadowCore are organized within the/events directory.
Example Folder Structure:
โ๏ธ Properties
The Event component allows you to specify the following properties:๐งฉ Usage
To define an event, create a newEvent instance and specify the event name (name), the function to run when the event triggers (run), and whether the event should only trigger once (once).
Hereโs an example of creating a ready event that registers commands when the bot is ready:
- The name is โreadyโ, which is the event that triggers when the bot logs in successfully.
- The run function registers the commands for the bot when itโs ready.
- The once property is set to true, so the event will only trigger once.
Handling Other Events
You can create events for any of the supported Discord.js events. For example, you could handle themessageCreate event to listen for new messages and respond accordingly.
Example of handling the messageCreate event:
- The
nameis"messageCreate", which triggers when a new message is sent. - The
runfunction checks if the message content is!pingand replies with"Pong!".
๐ Event Lifecycle
ShadowCore uses Discord.jsโs event system, and events likeready, messageCreate, and interactionCreate are just a few examples of the available events. You can register any event that Discord.js supports.
The interactionCreate is already handled by ShadowCore and does not need to be registered manually. It is automatically set up to handle interactions like buttons, select menus, and commands.For a full list of events supported by Discord.js, refer to the Discord.js documentation.