/run local n,u=4,"party" if IsInRaid() then n,u=40,"raid" end for i=n,1,-1 do if UnitExists(u..i) and not UnitIsUnit(u..i,"player") then UninviteUnit(u..i,nil,1) end end LeaveParty()