Wars

Clan War

class coc.ClanWar

Represents a Current Clash of Clans War

clan

WarClan: The home clan.

opponent

WarClan: The opposition clan.

state

str: The clan’s current war state.

preparation_start_time

Timestamp: The Timestamp that preparation day started at.

start_time

Timestamp: The Timestamp that battle day starts at.

end_time

Timestamp: The Timestamp that battle day ends at.

team_size

int: The number of players on each side of the war.

war_tag

str: The war’s unique tag. This is None unless this is a Clan League War (CWL).

league_group

ClanWarLeagueGroup: The war’s league group. This is None unless this is a Clan League War.

attacks_per_member

int: The number of attacks each member has this war.

clan_cls

the type war.clan and war.opponent will be of. Ensure any overriding of this inherits from coc.WarClan.

Type:

WarClan

property attacks: List[WarAttack]

Returns all attacks this war, sorted by attack order.

Type:

List[WarAttack]

get_attack(attacker_tag: str, defender_tag: str) Optional[WarAttack]

Return the WarAttack with the attacker tag and defender tag provided.

If the attack was not found, this will return None.

Returns:

The attack with the correct attacker and defender tags

Return type:

WarAttack:

get_defenses(defender_tag: str) List[WarAttack]

Return a list of WarAttack for the defender tag provided.

If the player has no defenses, this will return an empty list.

Returns:

The player’s defenses

Return type:

List[WarAttack]

get_member(tag: str) Optional[ClanWarMember]

Return a ClanWarMember with the tag provided. Returns None if not found.

Example

war = await client.get_current_war('clan_tag')
member = war.get_member('player_tag')
Returns:

Optional[:class:`ClanWarMember`]

Return type:

The member who matches the tag provided.

get_member_by(**attrs) Optional[ClanWarMember]

Returns the first WarMember that meets the attributes passed

This will return the first member matching the attributes passed.

An example of this looks like:

member = ClanWar.get_member(tag='tag')

This search implements the coc.utils.get() function

property is_cwl: bool

Returns a boolean indicating if the war is a Clan War League (CWL) war.

Type:

bool

property members: List[ClanWarMember]

A list of members that are in the war.

Type:

List[ClanWarMember]

property status: str

Returns the war status, based off the home clan.

Strings returned are determined by result and state, as listed below:

inWar

warEnded

winning

won

tied

tie

losing

lost

Type:

str

property type: Optional[str]

Returns either friendly, random or cwl.

This will returns None if the clan is not in war, or cwl if the clan is in a league war.

Possibilities for the length of preparation time for a friendly war include: 5 minutes, 15 minutes, 30 minutes, 1 hour, 2 hours, 4 hours, 6 hours, 8 hours, 12 hours, 16 hours, 20 hours or 24 hours.

Type:

str

Clan War Log Entry

class coc.ClanWarLogEntry

Represents a Clash of Clans War Log Entry

Note

Please see the WarClan documentation for a full list of missing attributes, as the clan and opponent attributes are only partially filled by the API.

If the ClanWarLogEntry.type is cwl, the WarClan.attack_count, WarClan.stars and WarClan.destruction are all a total which over the period of that CWL season.

In addition, if it is a CWL entry, opponent and result will be None.

result

str: The result of the war - win or loss

end_time

Timestamp: The Timestamp that the war ended at.

team_size

int: The number of players on each side of the war.

clan

WarClan: The home clan.

opponent

WarClan: The opposition clan.

attacks_per_member

int: The number of attacks each member had this war.

property is_league_entry: bool

Boolean indicating if the entry is a Clan War League (CWL) entry.

Type:

bool

Clan War League Group

class coc.ClanWarLeagueGroup

Represents a Clan War League (CWL) Group

state

str: The current state of the league group (inWar, preparation etc.)

season

str: The current season of the league group

number_of_rounds

int: The number of rounds this league group contains.

rounds

List[List[str]]: A list of lists containing all war tags for each round.

Note

This only returns the current or past rounds. Any future rounds filled with #0 war tags will not appear.

To find the number of rounds in this season, use LeagueGroup.number_of_rounds.

clans

Returns all participating clans.

Type:

List[LeagueClan]

get_wars(cwl_round: ~coc.enums.WarRound = WarRound.current_war, cls: ~typing.Type[~coc.wars.ClanWar] = <class 'coc.wars.ClanWar'>) AsyncIterator[ClanWar]

Returns war information for every war in a league round.

This returns a LeagueWarIterator which fetches all wars in parallel.

Example

group = await client.get_league_group('clan_tag')

async for war in group.get_wars():
    print(war.clan_tag)
Parameters:
  • cls (Type[ClanWar]: The constructor used to create the league war.) – This should inherit from ClanWar.

  • cwl_round (WarRound) – An enum detailing the type of round to get. Could be coc.WarRound.previous_war, coc.WarRound.current_war or coc.WarRound.preparation. This defaults to coc.WarRound.current_war.

Yields:

ClanWar – A war in the requested round.

get_wars_for_clan(clan_tag: str, cls: ~typing.Type[~coc.wars.ClanWar] = <class 'coc.wars.ClanWar'>) AsyncIterator[ClanWar]

Returns every war the clan has participated in this current CWL.

This returns a LeagueWarIterator which fetches all wars in parallel.

Example

group = await client.get_league_group('#clan_tag')

async for war in group.get_wars_for_clan('#clantag'):
    print(war.start_time)
Parameters:
  • clan_tag (str) – The clan tag to get wars for. This method will only return wars which belong to this clan.

  • cls (Type[ClanWar]: The constructor used to create the league war.) – This should inherit from ClanWar.

Yields:

ClanWar – A war in the current CWL season with the clan in it..

War Round

class coc.WarRound

An Enumeration with the following Clan War League War Round types.

previous_war
current_war
current_preparation

War Attack

class coc.WarAttack

Represents a Clash of Clans War Attack

war

ClanWar - The war this attack belongs to

stars

int - The stars achieved

destruction

float - The destruction achieved as a percentage (of 100)

order

int - The attack order in this war

attacker_tag

str - The attacker tag

defender_tag

str - The defender tag

duration

int - Duration of attack in seconds

property attacker: ClanWarMember

Returns the attacking player.

Type:

ClanWarMember

property defender: ClanWarMember

Returns the defending player.

Type:

ClanWarMember

property is_fresh_attack: bool

Returns whether the attack is a fresh (first) attack on the defender.

Type:

boolean