Skip to content

7) Adding events

Oğuzhan edited this page Jul 22, 2022 · 3 revisions

First create a file that ends with .js extension located in the directory you specified in the config.json's events.directory property.

Now you can just add your in-file config and start coding!

In-file config properties

name

This should be defined in your in-file config.

This will be used while registering the event.

Example event names: ready, guildMemberAdd

All events: https://discord.js.org/#/docs/discord.js/main/class/Client

enabled

This is an optional property and false by default.

If you want your command to get triggered by using it adds this property.

External variables

stop()

This stops your command and can have limitless arguments which won't matter.

args

An array that includes the arguments given to the event.

event

This is a NodeJS.Global.Event instance which represents the current event. You can get in-file config properties using it: event.getConfigValue("name")

Getting arguments

Normally you can register events like this:

client.on("eventName", (argument1, argument2, argument3) => {
  
});

Just like those argument1, argument2 and argument3 you can get arguments using args variable.

Like this:

const [argument1, argument2, argument3] = args;

So if your event is voiceStateChange you can get the old state and new state like this:

const [oldState, newState] = args;

Argument names are up to you so you can use oSt or something else for oldState too!