Create your first Event
What are Events?
Events are actions or occurrences recognized by software that might be handled by your program. In the context of Discord bots, events are various things that happen in connection with the server, such as messages being sent, users joining a server, or a user starting a voice chat. Handling these events allows your bot to react dynamically to what's happening on the server.
Importance of Events
Events are fundamental in creating interactive and responsive applications. In Discord bots, events allow the bot to engage with users in real time. For instance, by handling message events, a bot can respond to commands, answer questions, or moderate chat. The ability to handle events efficiently and effectively can greatly enhance the user experience, making your bot feel more alive and integrated into the server's daily operations.
Implementing Events (with messageCreate.js)
To define corectly the messageCreate
event, start by importing necessary elements from the umbrae
library and setting up the event structure with EventBuilder
. For the example below, we created the event with the path ./events/[dir]/messageCreate.js
.
Warning
In this path [dir]
represents a mid-level directory situated between the root events
directory and the specific event file (messageCreate.js
). This structure helps organize events into categorically relevant directories for better manageability and clarity.
You have 2 ways to create Events :
import { EventBuilder } from 'umbrae';
export default EventBuilder(
{
name: 'messageCreate',
description: 'When a message is sent.'
},
async (message) => {
console.log(message)
}
)
or
import { EventBuilder, Events } from 'umbrae';
export default EventBuilder(
{
name: Events.MessageCreate,
description: 'When a message is sent.'
},
async (message) => {
console.log(message)
}
)