Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord.js: Manually triggering events

I have a basic moderation bot in discord.js, written in node.js. I need to run some tests on the bots but to do so, I need to toggle an event. I know that node.js has an e.dispatchEvent(event) but, to my knowledge, discord.js does not have a function like that.

I was wondering what the equivalent of that would be.

like image 955
Silveradoz Avatar asked Dec 04 '22 18:12

Silveradoz


1 Answers

A Discord Client extends a Node.js EventEmitter, so you can use the EventEmitter#emit() method to call listener functions attached to the event. For example...

// Assuming 'client' is a Client, 'member' is a GuildMember
client.emit('guildMemberAdd', member);

You can find a complete list of events normally emitted by a Client here.

like image 147
Caltrop Avatar answered Jan 17 '23 17:01

Caltrop