Skip to main content

Class: Client

Represents Clash of Clans API Client.

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

Hierarchy

Constructors

constructor

new Client(options?)

Parameters

NameType
options?ClientOptions

Defined in

client/Client.ts:70

Properties

emit

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

Defined in

client/Client.ts:29


off

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

Defined in

client/Client.ts:32


on

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

Defined in

client/Client.ts:35


once

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

Defined in

client/Client.ts:38


removeAllListeners

removeAllListeners: <K>(event?: K) => Client & <S>(event?: Exclude<S, keyof IClientEvents>) => Client

Defined in

client/Client.ts:41


rest

rest: RESTManager

REST Handler of the client.

Defined in

client/Client.ts:68

Accessors

util

get util(): typeof Util

Contains various general-purpose utility methods.

Returns

typeof Util

Defined in

client/Client.ts:79

Methods

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

Defined in

client/Client.ts:91


setKeys

setKeys(keys): Client

Set Clash of Clans API keys.

Parameters

NameType
keysstring[]

Returns

Client

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[]>

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>

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[]>

Defined in

client/Client.ts:120


getCapitalRaidSeasons

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

Get capital raid seasons.

Parameters

NameType
tagstring
options?SearchOptions

Returns

Promise<CapitalRaidSeason[]>

Defined in

client/Client.ts:126


getClanWarLog

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

Get clan war log.

Parameters

NameType
clanTagstring
options?SearchOptions

Returns

Promise<ClanWarLog[]>

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>

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

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

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[]>

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[]>

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>

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>

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>

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[]>

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>

Defined in

client/Client.ts:262


getLeagues

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

Get a list of Leagues.

Parameters

NameType
options?SearchOptions

Returns

Promise<APILeague[]>

Defined in

client/Client.ts:268


getBuilderBaseLeagues

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

Get a list of Leagues.

Parameters

NameType
options?SearchOptions

Returns

Promise<APIBuilderBaseLeague[]>

Defined in

client/Client.ts:274


getCapitalLeagues

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

Get a list of Capital Leagues.

Parameters

NameType
options?SearchOptions

Returns

Promise<APICapitalLeague[]>

Defined in

client/Client.ts:280


getLeagueSeasons

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

Get Legend League season Ids.

Parameters

NameType
options?SearchOptions

Returns

Promise<string[]>

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[]>

Defined in

client/Client.ts:292


getWarLeagues

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

Get list of Clan War Leagues.

Parameters

NameType
options?SearchOptions

Returns

Promise<APIWarLeague[]>

Defined in

client/Client.ts:298


getLocations

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

Get list of Locations.

Parameters

NameType
options?SearchOptions

Returns

Promise<Location[]>

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[]>

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[]>

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[]>

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[]>

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[]>

Defined in

client/Client.ts:354


getClanLabels

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

Get list of clan labels.

Parameters

NameType
options?SearchOptions

Returns

Promise<APILabel[]>

Defined in

client/Client.ts:360


getPlayerLabels

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

Get list of player labels.

Parameters

NameType
options?SearchOptions

Returns

Promise<APILabel[]>

Defined in

client/Client.ts:366


getGoldPassSeason

getGoldPassSeason(options?): Promise<GoldPassSeason>

Get info about gold pass season.

Parameters

NameType
options?OverrideOptions

Returns

Promise<GoldPassSeason>

Defined in

client/Client.ts:372

Events

debug

debug: string

Emitted for general debugging information.

Defined in

client/Client.ts:49


error

error: string

Emitted when the client encounters an error.

Defined in

client/Client.ts:56