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
↳
PollingClient
Constructors
constructor
• new PollingClient(options?
)
Parameters
Name | Type |
---|---|
options? | PollingClientOptions |
Overrides
Defined in
Properties
inMaintenance
• inMaintenance: boolean
Defined in
emit
• emit: <K>(event
: K
, ...args
: IPollingEvents
[K
]) => boolean
& <S>(event
: Exclude
<S
, keyof IPollingEvents
>, ...args
: any
[]) => boolean
Inherited from
Defined in
off
• off: <K>(event
: K
, listener
: (...args
: IPollingEvents
[K
]) => void
) => PollingClient
& <S>(event
: Exclude
<S
, keyof IPollingEvents
>, listener
: (...args
: any
[]) => void
) => PollingClient
Inherited from
Defined in
on
• on: <K>(event
: K
, listener
: (...args
: IPollingEvents
[K
]) => void
) => PollingClient
& <S>(event
: Exclude
<S
, keyof IPollingEvents
>, listener
: (...args
: any
[]) => void
) => PollingClient
Inherited from
Defined in
once
• once: <K>(event
: K
, listener
: (...args
: IPollingEvents
[K
]) => void
) => PollingClient
& <S>(event
: Exclude
<S
, keyof IPollingEvents
>, listener
: (...args
: any
[]) => void
) => PollingClient
Inherited from
Defined in
removeAllListeners
• removeAllListeners: <K>(event?
: K
) => PollingClient
& <S>(event?
: Exclude
<S
, keyof IPollingEvents
>) => PollingClient
Inherited from
Defined in
rest
• rest: RESTManager
REST Handler of the client.
Inherited from
Defined in
Accessors
util
• get
util(): typeof Util
Contains various general-purpose utility methods.
Returns
typeof Util
Inherited from
Client.util
Defined in
Methods
init
▸ init(): Promise
<string
[]>
Initialize the PollingEvent Manager to start pulling the data by polling api.
Returns
Promise
<string
[]>
Defined in
addClans
▸ addClans(tags
): PollingClient
Add clan tags to clan polling events.
Parameters
Name | Type |
---|---|
tags | string | string [] |
Returns
Defined in
deleteClans
▸ deleteClans(tags
): PollingClient
Delete clan tags from clan polling events.
Parameters
Name | Type |
---|---|
tags | string | string [] |
Returns
Defined in
addPlayers
▸ addPlayers(tags
): PollingClient
Add player tags for player polling events.
Parameters
Name | Type |
---|---|
tags | string | string [] |
Returns
Defined in
deletePlayers
▸ deletePlayers(tags
): PollingClient
Delete player tags from player polling events.
Parameters
Name | Type |
---|---|
tags | string | string [] |
Returns
Defined in
addWars
▸ addWars(tags
): PollingClient
Add clan tags for war polling events.
Parameters
Name | Type |
---|---|
tags | string | string [] |
Returns
Defined in
deleteWars
▸ deleteWars(tags
): PollingClient
Delete clan tags from war polling events.
Parameters
Name | Type |
---|---|
tags | string | string [] |
Returns
Defined in
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
Name | Type |
---|---|
event | Object |
event.name | string |
event.filter | (oldClan : Clan , newClan : Clan ) => boolean |
Returns
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
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
Name | Type |
---|---|
event | Object |
event.name | string |
event.filter | (oldWar : ClanWar , newWar : ClanWar ) => boolean |
Returns
Defined in
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
Name | Type |
---|---|
event | Object |
event.name | string |
event.filter | (oldPlayer : Player , newPlayer : Player ) => boolean |
Returns
Defined in
login
▸ login(options
): Promise
<string
[]>
Initialize the client to create keys.
Parameters
Name | Type |
---|---|
options | LoginOptions |
Returns
Promise
<string
[]>
Example
const client = new Client();
client.login({ email: 'developer@email.com', password: '***' });
Inherited from
Defined in
setKeys
▸ setKeys(keys
): PollingClient
Set Clash of Clans API keys.
Parameters
Name | Type |
---|---|
keys | string [] |
Returns
Inherited from
Defined in
getClans
▸ getClans(query
, options?
): Promise
<Clan
[]>
Search clans by name and/or filtering parameters or get clans by their tags (fetches in parallel).
Parameters
Name | Type |
---|---|
query | string [] | ClanSearchOptions |
options? | OverrideOptions |
Returns
Promise
<Clan
[]>
Inherited from
Defined in
getClan
▸ getClan(clanTag
, options?
): Promise
<Clan
>
Get info about a clan.
Parameters
Name | Type |
---|---|
clanTag | string |
options? | OverrideOptions |
Returns
Promise
<Clan
>
Inherited from
Defined in
getClanMembers
▸ getClanMembers(clanTag
, options?
): Promise
<ClanMember
[]>
Get list of clan members.
Parameters
Name | Type |
---|---|
clanTag | string |
options? | SearchOptions |
Returns
Promise
<ClanMember
[]>
Inherited from
Defined in
getCapitalRaidSeasons
▸ getCapitalRaidSeasons(tag
, options?
): Promise
<CapitalRaidSeason
[]>
Get capital raid seasons.
Parameters
Name | Type |
---|---|
tag | string |
options? | SearchOptions |
Returns
Promise
<CapitalRaidSeason
[]>
Inherited from
Defined in
getClanWarLog
▸ getClanWarLog(clanTag
, options?
): Promise
<ClanWarLog
[]>
Get clan war log.
Parameters
Name | Type |
---|---|
clanTag | string |
options? | SearchOptions |
Returns
Promise
<ClanWarLog
[]>
Inherited from
Defined in
getClanWar
▸ getClanWar(clanTag
, options?
): Promise
<ClanWar
>
Get info about currently running war (normal or friendly) in the clan.
Parameters
Name | Type |
---|---|
clanTag | string |
options? | OverrideOptions |
Returns
Promise
<ClanWar
>
Inherited from
Defined in
getCurrentWar
▸ getCurrentWar(clanTag
, options?
): Promise
<null
| ClanWar
>
Get info about currently running war in the clan.
Parameters
Name | Type |
---|---|
clanTag | string | { 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
Defined in
getLeagueWar
▸ getLeagueWar(clanTag
, options?
): Promise
<null
| ClanWar
>
Get info about currently running CWL round.
Parameters
Name | Type |
---|---|
clanTag | string | { 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
Defined in
getLeagueWars
▸ getLeagueWars(clanTag
, options?
): Promise
<ClanWar
[]>
Returns active wars (last 2) of the CWL group.
Parameters
Name | Type |
---|---|
clanTag | string |
options? | OverrideOptions |
Returns
Promise
<ClanWar
[]>
Inherited from
Defined in
getWars
▸ getWars(clanTag
, options?
): Promise
<ClanWar
[]>
Returns active wars (last 2 for CWL) of the clan.
Parameters
Name | Type |
---|---|
clanTag | string |
options? | OverrideOptions |
Returns
Promise
<ClanWar
[]>
Inherited from
Defined in
getClanWarLeagueGroup
▸ getClanWarLeagueGroup(clanTag
, options?
): Promise
<ClanWarLeagueGroup
>
Get info about clan war league.
Parameters
Name | Type |
---|---|
clanTag | string |
options? | OverrideOptions |
Returns
Promise
<ClanWarLeagueGroup
>
Inherited from
Defined in
getClanWarLeagueRound
▸ getClanWarLeagueRound(warTag
, options?
): Promise
<ClanWar
>
Get info about a CWL round by WarTag.
Parameters
Name | Type |
---|---|
warTag | string | { warTag : string ; clanTag? : string } |
options? | OverrideOptions |
Returns
Promise
<ClanWar
>
Inherited from
Defined in
getPlayer
▸ getPlayer(playerTag
, options?
): Promise
<Player
>
Get info about a player by tag.
Parameters
Name | Type |
---|---|
playerTag | string |
options? | OverrideOptions |
Returns
Promise
<Player
>
Inherited from
Defined in
getPlayers
▸ getPlayers(playerTags
, options?
): Promise
<Player
[]>
Get info about some players by their tags (fetches in parallel).
Parameters
Name | Type |
---|---|
playerTags | string [] |
options? | OverrideOptions |
Returns
Promise
<Player
[]>
Inherited from
Defined in
verifyPlayerToken
▸ verifyPlayerToken(playerTag
, token
, options?
): Promise
<boolean
>
Verify Player API token that can be found from the Game settings.
Parameters
Name | Type |
---|---|
playerTag | string |
token | string |
options? | OverrideOptions |
Returns
Promise
<boolean
>
Inherited from
Defined in
getLeagues
▸ getLeagues(options?
): Promise
<APILeague
[]>
Get a list of Leagues.
Parameters
Name | Type |
---|---|
options? | SearchOptions |
Returns
Promise
<APILeague
[]>
Inherited from
Defined in
getBuilderBaseLeagues
▸ getBuilderBaseLeagues(options?
): Promise
<APIBuilderBaseLeague
[]>
Get a list of Leagues.
Parameters
Name | Type |
---|---|
options? | SearchOptions |
Returns
Promise
<APIBuilderBaseLeague
[]>
Inherited from
Defined in
getCapitalLeagues
▸ getCapitalLeagues(options?
): Promise
<APICapitalLeague
[]>
Get a list of Capital Leagues.
Parameters
Name | Type |
---|---|
options? | SearchOptions |
Returns
Promise
<APICapitalLeague
[]>
Inherited from
Defined in
getLeagueSeasons
▸ getLeagueSeasons(options?
): Promise
<string
[]>
Get Legend League season Ids.
Parameters
Name | Type |
---|---|
options? | SearchOptions |
Returns
Promise
<string
[]>
Inherited from
Defined in
getSeasonRankings
▸ getSeasonRankings(seasonId
, options?
): Promise
<SeasonRankedPlayer
[]>
Get Legend League season rankings by season Id.
Parameters
Name | Type |
---|---|
seasonId | string |
options? | SearchOptions |
Returns
Promise
<SeasonRankedPlayer
[]>
Inherited from
Defined in
getWarLeagues
▸ getWarLeagues(options?
): Promise
<APIWarLeague
[]>
Get list of Clan War Leagues.
Parameters
Name | Type |
---|---|
options? | SearchOptions |
Returns
Promise
<APIWarLeague
[]>
Inherited from
Defined in
getLocations
▸ getLocations(options?
): Promise
<Location
[]>
Get list of Locations.
Parameters
Name | Type |
---|---|
options? | SearchOptions |
Returns
Promise
<Location
[]>
Inherited from
Defined in
getClanRanks
▸ getClanRanks(locationId
, options?
): Promise
<RankedClan
[]>
Get clan rankings for a specific location.
For global ranking, use global
as locationId
.
Parameters
Name | Type |
---|---|
locationId | number | "global" |
options? | SearchOptions |
Returns
Promise
<RankedClan
[]>
Inherited from
Defined in
getPlayerRanks
▸ getPlayerRanks(locationId
, options?
): Promise
<RankedPlayer
[]>
Get player rankings for a specific location.
For global ranking, use global
as locationId
.
Parameters
Name | Type |
---|---|
locationId | number | "global" |
options? | SearchOptions |
Returns
Promise
<RankedPlayer
[]>
Inherited from
Defined in
getBuilderBaseClanRanks
▸ getBuilderBaseClanRanks(locationId
, options?
): Promise
<RankedClan
[]>
Get clan builder base rankings for a specific location.
For global ranking, use global
as locationId
.
Parameters
Name | Type |
---|---|
locationId | number | "global" |
options? | SearchOptions |
Returns
Promise
<RankedClan
[]>
Inherited from
Client.getBuilderBaseClanRanks
Defined in
getBuilderBasePlayerRanks
▸ getBuilderBasePlayerRanks(locationId
, options?
): Promise
<RankedPlayer
[]>
Get player builder base rankings for a specific location.
For global ranking, use global
as locationId
.
Parameters
Name | Type |
---|---|
locationId | number | "global" |
options? | SearchOptions |
Returns
Promise
<RankedPlayer
[]>
Inherited from
Client.getBuilderBasePlayerRanks
Defined in
getClanCapitalRanks
▸ getClanCapitalRanks(locationId
, options?
): Promise
<APIClanCapitalRanking
[]>
Get clan capital rankings for a specific location.
For global ranking, use global
as locationId
.
Parameters
Name | Type |
---|---|
locationId | number | "global" |
options? | SearchOptions |
Returns
Promise
<APIClanCapitalRanking
[]>
Inherited from
Defined in
getClanLabels
▸ getClanLabels(options?
): Promise
<APILabel
[]>
Get list of clan labels.
Parameters
Name | Type |
---|---|
options? | SearchOptions |
Returns
Promise
<APILabel
[]>
Inherited from
Defined in
getPlayerLabels
▸ getPlayerLabels(options?
): Promise
<APILabel
[]>
Get list of player labels.
Parameters
Name | Type |
---|---|
options? | SearchOptions |
Returns
Promise
<APILabel
[]>
Inherited from
Defined in
getGoldPassSeason
▸ getGoldPassSeason(options?
): Promise
<GoldPassSeason
>
Get info about gold pass season.
Parameters
Name | Type |
---|---|
options? | OverrideOptions |
Returns
Promise
<GoldPassSeason
>
Inherited from
Defined in
Events
newSeasonStart
• newSeasonStart: string
Emits when a new season starts.
Parameters
Name | Type | Description |
---|---|---|
id | string | Id of the new season. |
Defined in
maintenanceStart
• maintenanceStart: string
Emits when maintenance break starts in the API.
Defined in
maintenanceEnd
• maintenanceEnd: string
Emits when maintenance break ends in the API.
Parameters
Name | Type | Description |
---|---|---|
duration | number | Duration of the maintenance break in milliseconds. |
Defined in
debug
• debug: string
Emitted for general debugging information.
Inherited from
Defined in
error
• error: string
Emitted when the client encounters an error.