Skip to content

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!

Event list

How the event handling system works?

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
});

List of events

Event win

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!');
});

Event tie

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!');
});