In recent years, there has been a growing interest in integrating distributed generation (DG) technologies into the distribution network (DN) to improve system efficiency, reduce carbon emissions, and increase the power system's reliability. However, the optimal placement of DG systems within the DN is a difficult task, since it is dependent on several variables, including load demand, renewable energy sources, and energy storage systems (ESS). In this context, demand response (DR) programs can play a vital role in enhancing the efficiency of DG systems, since they allow consumers to lower their energy usage during peak hours and move their demand to off-peak hours. DR and solar photovoltaic (SPV) systems are two prominent technologies that can play a substantial role in the power DN. In this paper, a bi-level particle swarm optimization (PSO) method is employed to determine the best allocation of DG in the coordination of DR. In the suggested methodology, the first level of optimization determines the optimal size and location of DG, and the second level of optimization determines the optimal power dispatch in the coordination of DR. The proposed method is implemented on the IEEE 33 bus system, and the results demonstrate that the power quality parameters have significantly improved.