As confirmed later, a way to avoid this is to look at the information about the defending party shown in a battle report:
Since older battle reports for the same village still show barbarians as the owner, the bot should remember that it has seen a report for this village which implies that it should not attack there. It could then emit a log message like this when skipping the report:
The details of another report (‘Caption of the report here’) for the same village indicate that I should not attack at (123|567). I skip this report.
This log message allows the user to look up the report which led to the decision to skip.
One thing to note about this approach is that it depends on appropriate filter settings in the report list. The user should not filter out reports with casualties, as this may hide the report indicating the new ownership.
But there are other ways to check if it is still a barbarian village. As I can see so far, it looks like the game gives us a reliable way to check for barbarians with the menu item to Boost Production:
In 2020, I developed a new version from scratch. The 2020 version does not depend on battle reports but instead searches the map for barbarian villages. The new bot rereads the village information every time before attacking the village. That means it notices if the village has been conquered by a player and so avoid attacking that player.
The complete guide for the 2020 edition of the farmbot is in this topic: