Game

Game

The base class for all games, see Getting Started to get started.

Constructor

(abstract) new Game(msg, settings)

Creates a new game.

Source:
Parameters:
Name Type Description
msg Discord.Message

The message object.

settings GameSettings

An optional object with custom settings for the game

Members

channel :Discord.TextChannel

The Discord channel that this game is played in.

Source:
See:
Type:

client :Discord.Client

The Discord client that this game belongs to.

Source:
See:
Type:

collectors :Array.<Discord.Collector>

A list of Discord collectors that is cleared when this.clearCollectors(this.collectors) is called. Whenever a MessageCollector or ReactionCollector is created, push it to this.collectors().

Deprecated:
  • Yes
Source:
See:
Type:
  • Array.<Discord.Collector>

ending :Boolean

Helper field that is only true when this.forceStop() is called. This should be used to prevent the game from continuing when unexpectedly ended.

Source:
Type:
  • Boolean
Example
const collector = this.channel.createMessageCollector(filter, options)
collector.on('message', message => {
    if(this.ending) return
    // ...
})

gameMaster :Discord.User

The Discord user who initialized this game.

Source:
See:
Type:

gameOptions :Array.<GameOption>

The list of user-configurable options for this game. The configured options will be accessible from this.options[friendlyName] after the init stage.

Source:
Type:
Example
this.gameOptions = [
    {
        friendlyName: 'Categories',
        type: 'checkboxes'
        default: ['Game of Thrones']
        choices: ['Game of Thrones', 'Narnia', 'Lord of the Rings', 'Harry Potter'],
        note: 'Choose the categories for this game.'
    },
    {
        friendlyName: 'Game Mode',
        type: 'radio',
        default: 'Solo',
        choices: ['Team', 'Solo'],
        note: 'In team, players are matched up against each other in groups. In solo, it\'s everyone for themself!'
    },
    {
        friendlyName: 'Timer',
        type: 'number',
        default: 60,
        note: 'Enter a new value in seconds, between 30-60.',
        filter: m => parseInt(m.content) >= 30 && parseInt(m.content) <= 60
    },
    {
        friendlyName: 'Clan Tag',
        type: 'free',
        default: 'none',
        note: 'Enter a new 3-letter clan tag, or type \'none\' for no name.',
        filter: m => m.content.length == 3 || m.content == 'none'
    }
]

leader

Source:
See:

metadata :GameMetadata

The metadata from the game, typically read from a metadata.json file.

Source:
Type:
Example
this.metadata = require('./metadata.json')

msg :Discord.Message

The Discord message that initialized this game.

Source:
See:
Type:
  • Discord.Message

playerCount :Object

The game's minimum and maximum player count. Use this.metadata instead.

Properties:
Name Type Description
min Number

The minimum player count for this game.

max Number

The maximum player count for this game.

Deprecated:
  • Yes
Source:
Type:
  • Object

players :Discord.Collection

The collection of players who are added to this game during the join phase.

Source:
See:
Type:
  • Discord.Collection

playersToAdd :Array

An array of players that are queued to be added, populated using the this.addPlayer() command

Source:
Type:
  • Array

playersToKick :Array

An array of players that are queued to be added, populated using the this.removePlayer() command

Source:
Type:
  • Array

settings

Game-specific settings that are configurable on a class level.

Source:

stage :String

The current stage of the game. Default stages include 'join' and 'init'.

Source:
Type:
  • String

Methods

(async) addPlayer(member, message)

Add a player to the queue to be added to the game.

Source:
Parameters:
Name Type Description
member Discord.Member | string

The member or id of the member to add

message string

The message to send if the user is successfully queued. Set to "null" for no message to be sent.

(async) clearCollectors(collectors)

Stop all collectors and reset collector list.

Deprecated:
  • Yes
Source:
Parameters:
Name Type Description
collectors Array.<Discord.Collector>

List of collectors

(async) configureOptions() → {Object.<String, ConfiguredOption>}

Allow the game leader to set options, and outputs the options to this.options.

Source:
Returns:
Type:
Object.<String, ConfiguredOption>

The configured options, with their key as the option friendly name, and value as the configured value.

end(winner, endPhrase)

End a game. This will be called when a player wins or the game is force stopped.

Source:
Parameters:
Name Type Description
winner object

The game winner

endPhrase string

The message to be sent at the end of the game.

forceStop()

Force ends a game. This will be called by the end command.

Source:

(async, abstract) generateOptions()

Generates option lists, each game implements this method in its own way.

Source:

(async) init()

Begins a new game. This will be called by the play command.

Source:

(async) join(callback)

Begins the join phase of the game.

Source:
Parameters:
Name Type Description
callback function

The callback that is executed when the players are collected.

messageListener()

The message listener wrapper function. Whenever a message is sent, the message is handled by the this.onMessage(msg) callback in order to provide custom command functionality.

Source:

(async) onMessage(message)

Handles message events emitted by the client.

Source:
Parameters:
Name Type Description
message Discord.Message

The message emitted by the client.

(abstract) play()

The method called after user configuration. This will be custom for each game.

Source:

(async) removePlayer(member, message)

Add a player to the queue to be removed from the game.

Source:
Parameters:
Name Type Description
member string | Discord.Member

The member or member id to kick.

message string

The message to send if the user is successfully queued. Set to "null" for no message to be sent.

renderOptionInfo(option)

Display the choices of a game's option.

Source:
Parameters:
Name Type Description
option GameOption

The option to render into text.

updatePlayers()

Update players who are queued to join or leave the game.

Source: