-
Notifications
You must be signed in to change notification settings - Fork 37
Event handling system
Maxime Malgorn edited this page Mar 12, 2021
·
2 revisions
Are you using custom dependencies to manage an economy, a leaderboard?
You can link the TicTacToe module to whatever your want thanks to custom events!
Connect the TicTacToe bot:
const TicTacToe = require('discord-tictactoe');
const bot = new TicTacToe({ language: 'en', command: '!ttt' });
bot.login('YOUR_BOT_TOKEN')
.then(() => console.log('TicTacToe bot is ready to be used.'));
Usage:
bot.on('EVENT', data => {
// "EVENT" is the name of the event
// "data" is the object with event data
});
Triggered when a guild member wins a game.
Example of data object:
{
"winner": {
"id": "123456789123456",
"displayName": "Maxime โ Utarwyn"
},
"loser": {
"id": "AI",
"displayName": "the AI",
}
}
Example of code usage:
bot.on('win', data => {
console.log(data.winner + ' wins the TicTacToe game!');
console.log(data.loser + ' loses the TicTacToe game!');
});
Triggered when two players make a draw.
Example of data object:
{
"players": [
{
"id": "AI",
"displayName": "the AI"
},
{
"id": "123456789123456",
"displayName": "Maxime โ Utarwyn"
}
]
}
Example of code usage:
bot.on('tie', data => {
console.log(data.players[0] + ' and ' + data.players[1] + ' made a draw!');
});