Increasing the number of participants in energy communities leads to a new challenge in power systems, which is finding the optimal strategy for community members. Accordingly, this paper presents a distributed model for determining the optimal energy trading strategy of community participants such as buyers, sellers, and the community manager (CM). In the proposed model, the local day-ahead energy market, peer-to-peer (P2P) contracts, and the power grid are considered for trading energy between participants as well as compensating for power shortages/surpluses in the community. To model the uncertainty of PV generation, and selling/buying prices of the distribution network, the robust optimization (RO) approach is used. According to the defined budget of uncertainty, the optimal strategies of community members are determined based on the worst-case realizations of uncertain parameters. To decrease the solution time, the distributed optimization method is addressed. Accordingly, the augmented Lagrangian relaxation (ALR) and the alternating direction method of multipliers (ADMM) methods are used to decompose the optimization problem. The performance of the proposed model is evaluated through a case study. Simulation results demonstrate that the proposed model reduces the solution time of energy management problem in communities, significantly. (c) 2023 The Author(s). Published by Elsevier Ltd. This is an open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/).