Skip to main content

Class: PollingClient

Represents a Polling Event Client.

const { PollingClient } = require('clashofclans.js');
const pollingClient = new PollingClient({ keys: ['***'] });

Deprecated

The API lacks socket-based real-time events. It is recommended to implement your own custom polling system. Pull data at specified intervals, compare with previous values, and emit events on change. Consider using Node.js clusters for efficient parallel processing.

Hierarchy

Constructors

constructor

new PollingClient(options?)

Parameters

NameType
options?PollingClientOptions

Overrides

Client.constructor

Defined in

client/PollingClient.ts:45

Properties

inMaintenance

inMaintenance: boolean

Defined in

client/PollingClient.ts:42


emit

emit: <K>(event: K, ...args: IPollingEvents[K]) => boolean & <S>(event: Exclude<S, keyof IPollingEvents>, ...args: any[]) => boolean

Inherited from

Client.emit

Defined in

client/PollingClient.ts:326


off

off: <K>(event: K, listener: (...args: IPollingEvents[K]) => void) => PollingClient & <S>(event: Exclude<S, keyof IPollingEvents>, listener: (...args: any[]) => void) => PollingClient

Inherited from

Client.off

Defined in

client/PollingClient.ts:329


on

on: <K>(event: K, listener: (...args: IPollingEvents[K]) => void) => PollingClient & <S>(event: Exclude<S, keyof IPollingEvents>, listener: (...args: any[]) => void) => PollingClient

Inherited from

Client.on

Defined in

client/PollingClient.ts:332


once

once: <K>(event: K, listener: (...args: IPollingEvents[K]) => void) => PollingClient & <S>(event: Exclude<S, keyof IPollingEvents>, listener: (...args: any[]) => void) => PollingClient

Inherited from

Client.once

Defined in

client/PollingClient.ts:335


removeAllListeners

removeAllListeners: <K>(event?: K) => PollingClient & <S>(event?: Exclude<S, keyof IPollingEvents>) => PollingClient

Inherited from

Client.removeAllListeners

Defined in

client/PollingClient.ts:338


rest

rest: RESTManager

REST Handler of the client.

Inherited from

Client.rest

Defined in

client/Client.ts:68

Accessors

util

get util(): typeof Util

Contains various general-purpose utility methods.

Returns

typeof Util

Inherited from

Client.util

Defined in

client/Client.ts:79

Methods

init

init(): Promise<string[]>

Initialize the PollingEvent Manager to start pulling the data by polling api.

Returns

Promise<string[]>

Defined in

client/PollingClient.ts:59


addClans

addClans(tags): PollingClient

Add clan tags to clan polling events.

Parameters

NameType
tagsstring | string[]

Returns

PollingClient

Defined in

client/PollingClient.ts:71


deleteClans

deleteClans(tags): PollingClient

Delete clan tags from clan polling events.

Parameters

NameType
tagsstring | string[]

Returns

PollingClient

Defined in

client/PollingClient.ts:79


addPlayers

addPlayers(tags): PollingClient

Add player tags for player polling events.

Parameters

NameType
tagsstring | string[]

Returns

PollingClient

Defined in

client/PollingClient.ts:89


deletePlayers

deletePlayers(tags): PollingClient

Delete player tags from player polling events.

Parameters

NameType
tagsstring | string[]

Returns

PollingClient

Defined in

client/PollingClient.ts:97


addWars

addWars(tags): PollingClient

Add clan tags for war polling events.

Parameters

NameType
tagsstring | string[]

Returns

PollingClient

Defined in

client/PollingClient.ts:107


deleteWars

deleteWars(tags): PollingClient

Delete clan tags from war polling events.

Parameters

NameType
tagsstring | string[]

Returns

PollingClient

Defined in

client/PollingClient.ts:115


setClanEvent

setClanEvent(event): PollingClient

Set your own custom clan polling event.

In order to emit the custom polling event, you must have this filter function that returns a boolean.

Parameters

NameType
eventObject
event.namestring
event.filter(oldClan: Clan, newClan: Clan) => boolean

Returns

PollingClient

Example

client.addClans(['#2PP', '#8QU8J9LP']);

client.setClanEvent({
name: 'clanMemberUpdate',
filter: (oldClan, newClan) => {
return oldClan.memberCount !== newClan.memberCount;
}
});

client.on('clanMemberUpdate', (oldClan, newClan) => {
console.log(oldClan.memberCount, newClan.memberCount);
});

(async function () {
await client.init();
})();

Defined in

client/PollingClient.ts:151


setWarEvent

setWarEvent(event): PollingClient

Set your own custom war event.

In order to emit the custom event, you must have this filter function that returns a boolean.

Parameters

NameType
eventObject
event.namestring
event.filter(oldWar: ClanWar, newWar: ClanWar) => boolean

Returns

PollingClient

Defined in

client/PollingClient.ts:164


setPlayerEvent

setPlayerEvent(event): PollingClient

Set your own custom player event.

In order to emit the custom event, you must have this filter function that returns a boolean.

Parameters

NameType
eventObject
event.namestring
event.filter(oldPlayer: Player, newPlayer: Player) => boolean

Returns

PollingClient

Defined in

client/PollingClient.ts:177


login

login(options): Promise<string[]>

Initialize the client to create keys.

Parameters

NameType
optionsLoginOptions

Returns

Promise<string[]>

Example

const client = new Client();
client.login({ email: 'developer@email.com', password: '***' });

Inherited from

Client.login

Defined in

client/Client.ts:91


setKeys

setKeys(keys): PollingClient

Set Clash of Clans API keys.

Parameters

NameType
keysstring[]

Returns

PollingClient

Inherited from

Client.setKeys

Defined in

client/Client.ts:96


getClans

getClans(query, options?): Promise<Clan[]>

Search clans by name and/or filtering parameters or get clans by their tags (fetches in parallel).

Parameters

NameType
querystring[] | ClanSearchOptions
options?OverrideOptions

Returns

Promise<Clan[]>

Inherited from

Client.getClans

Defined in

client/Client.ts:102


getClan

getClan(clanTag, options?): Promise<Clan>

Get info about a clan.

Parameters

NameType
clanTagstring
options?OverrideOptions

Returns

Promise<Clan>

Inherited from

Client.getClan

Defined in

client/Client.ts:114


getClanMembers

getClanMembers(clanTag, options?): Promise<ClanMember[]>

Get list of clan members.

Parameters

NameType
clanTagstring
options?SearchOptions

Returns

Promise<ClanMember[]>

Inherited from

Client.getClanMembers

Defined in

client/Client.ts:120


getCapitalRaidSeasons

getCapitalRaidSeasons(tag, options?): Promise<CapitalRaidSeason[]>

Get capital raid seasons.

Parameters

NameType
tagstring
options?SearchOptions

Returns

Promise<CapitalRaidSeason[]>

Inherited from

Client.getCapitalRaidSeasons

Defined in

client/Client.ts:126


getClanWarLog

getClanWarLog(clanTag, options?): Promise<ClanWarLog[]>

Get clan war log.

Parameters

NameType
clanTagstring
options?SearchOptions

Returns

Promise<ClanWarLog[]>

Inherited from

Client.getClanWarLog

Defined in

client/Client.ts:132


getClanWar

getClanWar(clanTag, options?): Promise<ClanWar>

Get info about currently running war (normal or friendly) in the clan.

Parameters

NameType
clanTagstring
options?OverrideOptions

Returns

Promise<ClanWar>

Inherited from

Client.getClanWar

Defined in

client/Client.ts:138


getCurrentWar

getCurrentWar(clanTag, options?): Promise<null | ClanWar>

Get info about currently running war in the clan.

Parameters

NameType
clanTagstring | { clanTag: string ; round?: "PreviousRound" | "CurrentRound" | "NextRound" }
options?OverrideOptions

Returns

Promise<null | ClanWar>

Example

await client.getCurrentWar('#8QU8J9LP');

Example

await client.getCurrentWar({ clanTag: '#8QU8J9LP', round: 'PREVIOUS_ROUND' });

Inherited from

Client.getCurrentWar

Defined in

client/Client.ts:154


getLeagueWar

getLeagueWar(clanTag, options?): Promise<null | ClanWar>

Get info about currently running CWL round.

Parameters

NameType
clanTagstring | { clanTag: string ; round?: "PreviousRound" | "CurrentRound" | "NextRound" }
options?OverrideOptions

Returns

Promise<null | ClanWar>

Example

await client.getLeagueWar('#8QU8J9LP');

Example

await client.getLeagueWar({ clanTag: '#8QU8J9LP', round: 'PREVIOUS_ROUND' });

Inherited from

Client.getLeagueWar

Defined in

client/Client.ts:182


getLeagueWars

getLeagueWars(clanTag, options?): Promise<ClanWar[]>

Returns active wars (last 2) of the CWL group.

Parameters

NameType
clanTagstring
options?OverrideOptions

Returns

Promise<ClanWar[]>

Inherited from

Client.getLeagueWars

Defined in

client/Client.ts:213


getWars

getWars(clanTag, options?): Promise<ClanWar[]>

Returns active wars (last 2 for CWL) of the clan.

Parameters

NameType
clanTagstring
options?OverrideOptions

Returns

Promise<ClanWar[]>

Inherited from

Client.getWars

Defined in

client/Client.ts:219


getClanWarLeagueGroup

getClanWarLeagueGroup(clanTag, options?): Promise<ClanWarLeagueGroup>

Get info about clan war league.

Parameters

NameType
clanTagstring
options?OverrideOptions

Returns

Promise<ClanWarLeagueGroup>

Inherited from

Client.getClanWarLeagueGroup

Defined in

client/Client.ts:236


getClanWarLeagueRound

getClanWarLeagueRound(warTag, options?): Promise<ClanWar>

Get info about a CWL round by WarTag.

Parameters

NameType
warTagstring | { warTag: string ; clanTag?: string }
options?OverrideOptions

Returns

Promise<ClanWar>

Inherited from

Client.getClanWarLeagueRound

Defined in

client/Client.ts:242


getPlayer

getPlayer(playerTag, options?): Promise<Player>

Get info about a player by tag.

Parameters

NameType
playerTagstring
options?OverrideOptions

Returns

Promise<Player>

Inherited from

Client.getPlayer

Defined in

client/Client.ts:249


getPlayers

getPlayers(playerTags, options?): Promise<Player[]>

Get info about some players by their tags (fetches in parallel).

Parameters

NameType
playerTagsstring[]
options?OverrideOptions

Returns

Promise<Player[]>

Inherited from

Client.getPlayers

Defined in

client/Client.ts:255


verifyPlayerToken

verifyPlayerToken(playerTag, token, options?): Promise<boolean>

Verify Player API token that can be found from the Game settings.

Parameters

NameType
playerTagstring
tokenstring
options?OverrideOptions

Returns

Promise<boolean>

Inherited from

Client.verifyPlayerToken

Defined in

client/Client.ts:262


getLeagues

getLeagues(options?): Promise<APILeague[]>

Get a list of Leagues.

Parameters

NameType
options?SearchOptions

Returns

Promise<APILeague[]>

Inherited from

Client.getLeagues

Defined in

client/Client.ts:268


getBuilderBaseLeagues

getBuilderBaseLeagues(options?): Promise<APIBuilderBaseLeague[]>

Get a list of Leagues.

Parameters

NameType
options?SearchOptions

Returns

Promise<APIBuilderBaseLeague[]>

Inherited from

Client.getBuilderBaseLeagues

Defined in

client/Client.ts:274


getCapitalLeagues

getCapitalLeagues(options?): Promise<APICapitalLeague[]>

Get a list of Capital Leagues.

Parameters

NameType
options?SearchOptions

Returns

Promise<APICapitalLeague[]>

Inherited from

Client.getCapitalLeagues

Defined in

client/Client.ts:280


getLeagueSeasons

getLeagueSeasons(options?): Promise<string[]>

Get Legend League season Ids.

Parameters

NameType
options?SearchOptions

Returns

Promise<string[]>

Inherited from

Client.getLeagueSeasons

Defined in

client/Client.ts:286


getSeasonRankings

getSeasonRankings(seasonId, options?): Promise<SeasonRankedPlayer[]>

Get Legend League season rankings by season Id.

Parameters

NameType
seasonIdstring
options?SearchOptions

Returns

Promise<SeasonRankedPlayer[]>

Inherited from

Client.getSeasonRankings

Defined in

client/Client.ts:292


getWarLeagues

getWarLeagues(options?): Promise<APIWarLeague[]>

Get list of Clan War Leagues.

Parameters

NameType
options?SearchOptions

Returns

Promise<APIWarLeague[]>

Inherited from

Client.getWarLeagues

Defined in

client/Client.ts:298


getLocations

getLocations(options?): Promise<Location[]>

Get list of Locations.

Parameters

NameType
options?SearchOptions

Returns

Promise<Location[]>

Inherited from

Client.getLocations

Defined in

client/Client.ts:304


getClanRanks

getClanRanks(locationId, options?): Promise<RankedClan[]>

Get clan rankings for a specific location.

For global ranking, use global as locationId.

Parameters

NameType
locationIdnumber | "global"
options?SearchOptions

Returns

Promise<RankedClan[]>

Inherited from

Client.getClanRanks

Defined in

client/Client.ts:314


getPlayerRanks

getPlayerRanks(locationId, options?): Promise<RankedPlayer[]>

Get player rankings for a specific location.

For global ranking, use global as locationId.

Parameters

NameType
locationIdnumber | "global"
options?SearchOptions

Returns

Promise<RankedPlayer[]>

Inherited from

Client.getPlayerRanks

Defined in

client/Client.ts:324


getBuilderBaseClanRanks

getBuilderBaseClanRanks(locationId, options?): Promise<RankedClan[]>

Get clan builder base rankings for a specific location.

For global ranking, use global as locationId.

Parameters

NameType
locationIdnumber | "global"
options?SearchOptions

Returns

Promise<RankedClan[]>

Inherited from

Client.getBuilderBaseClanRanks

Defined in

client/Client.ts:334


getBuilderBasePlayerRanks

getBuilderBasePlayerRanks(locationId, options?): Promise<RankedPlayer[]>

Get player builder base rankings for a specific location.

For global ranking, use global as locationId.

Parameters

NameType
locationIdnumber | "global"
options?SearchOptions

Returns

Promise<RankedPlayer[]>

Inherited from

Client.getBuilderBasePlayerRanks

Defined in

client/Client.ts:344


getClanCapitalRanks

getClanCapitalRanks(locationId, options?): Promise<APIClanCapitalRanking[]>

Get clan capital rankings for a specific location.

For global ranking, use global as locationId.

Parameters

NameType
locationIdnumber | "global"
options?SearchOptions

Returns

Promise<APIClanCapitalRanking[]>

Inherited from

Client.getClanCapitalRanks

Defined in

client/Client.ts:354


getClanLabels

getClanLabels(options?): Promise<APILabel[]>

Get list of clan labels.

Parameters

NameType
options?SearchOptions

Returns

Promise<APILabel[]>

Inherited from

Client.getClanLabels

Defined in

client/Client.ts:360


getPlayerLabels

getPlayerLabels(options?): Promise<APILabel[]>

Get list of player labels.

Parameters

NameType
options?SearchOptions

Returns

Promise<APILabel[]>

Inherited from

Client.getPlayerLabels

Defined in

client/Client.ts:366


getGoldPassSeason

getGoldPassSeason(options?): Promise<GoldPassSeason>

Get info about gold pass season.

Parameters

NameType
options?OverrideOptions

Returns

Promise<GoldPassSeason>

Inherited from

Client.getGoldPassSeason

Defined in

client/Client.ts:372

Events

newSeasonStart

newSeasonStart: string

Emits when a new season starts.

Parameters

NameTypeDescription
idstringId of the new season.

Defined in

client/PollingClient.ts:352


maintenanceStart

maintenanceStart: string

Emits when maintenance break starts in the API.

Defined in

client/PollingClient.ts:359


maintenanceEnd

maintenanceEnd: string

Emits when maintenance break ends in the API.

Parameters

NameTypeDescription
durationnumberDuration of the maintenance break in milliseconds.

Defined in

client/PollingClient.ts:372


debug

debug: string

Emitted for general debugging information.

Inherited from

Client.debug

Defined in

client/PollingClient.ts:379


error

error: string

Emitted when the client encounters an error.

Inherited from

Client.error

Defined in

client/PollingClient.ts:386